LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-18-2010, 11:38 AM   #1
ghantauke
Member
 
Registered: Nov 2010
Posts: 114

Rep: Reputation: 6
functions in perl such as tr, s etc


The functions such as s can only be used for variables such as $variable.
Is there any way to use it with arrays too so that it substitutes for each string in all of the array indexes.
I know we can do it using foreach loop or any other loop. But is there any inbuilt function to do it? It'd save me a lot of time. Thanks in advance.
 
Old 11-18-2010, 03:07 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
No.

"Regular expressions" act on "strings".

Not arrays.

Sorry
 
Old 11-18-2010, 05:27 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
perldoc -f map

--- rod.
 
Old 11-18-2010, 09:11 PM   #4
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, theNBomr -

Cool - I never knew that Thank you.

However, perldoc also goes on to say that a straightforward "foreach" is usually preferable:
Quote:
Note that $_ is an alias to the list value, so it
can be used to modify the elements of the LIST.
While this is useful and supported, it can cause
bizarre results if the elements of LIST are not
variables. Using a regular "foreach" loop for
this purpose would be clearer in most cases.
 
Old 11-19-2010, 12:52 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Yes, as usual in Perl, there's more than one way to do almost anything.
--- rod.
 
Old 11-19-2010, 08:57 AM   #6
ghantauke
Member
 
Registered: Nov 2010
Posts: 114

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by theNbomr View Post
Yes, as usual in Perl, there's more than one way to do almost anything.
--- rod.
Thanks for the reply guyz.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 12:01 PM
Calling KDE/C++ functions from python/perl and vice versa yogeshm02 Programming 1 04-30-2005 11:54 AM
Do Perl functions usually modify variables, or return modified copies? Why? johnMG Programming 3 02-06-2005 10:22 PM
overloading built-in functions in perl bigearsbilly Programming 0 11-12-2004 07:19 AM
pointers to functions/member functions champ Programming 2 03-28-2003 06:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration