Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-07-2006, 04:24 AM   #1
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Rep: Reputation: 30
Passing parameters to PERL script

Is it possible to pass parameters to a perl script? I can do it with a bash script but not sure if it can be done with perl?

[paddy@paddy tmp]$ cat

echo $0
echo $1
[paddy@paddy tmp]$ ./ "Test input"
Test input
[paddy@paddy tmp]$
Also is there a way to loop through the input parameters? I need to be able to send a list of files to my perl script and have it prefrom an action on each one.

Old 03-07-2006, 04:53 AM   #2
Registered: Apr 2005
Location: Sydney
Distribution: FC5
Posts: 174

Original Poster
Rep: Reputation: 30
Ok figured it out!


my $argc = 0;
    foreach my $arg (@ARGV) {
        printf "Argument %2d: '%s'\n", ++ $argc, $arg;
Old 03-07-2006, 05:18 AM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 199Reputation: 199
perl -h

If you want to do something for each input file, then
while (<>) {
   blah blah
will iterate through a list of files on the command line (placed in @ARGV) or stdin.,

you can use the -p -n switches (perl -h)
which will assume a loop for you,

eg: perl -p -e 's/THIS/THAT/' will do it for each file or stdin
Old 03-07-2006, 11:04 AM   #4
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
Why don't you just:

foreach (@ARGV) {
  print "$_ \n";


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Passing parameters to a shell script neocookie Linux - General 5 10-20-2005 11:44 AM
Passing parameters to bash script Kamikazee Programming 4 10-01-2005 06:41 AM
passing parameters to functions in shell script kushalkoolwal Programming 1 09-28-2005 02:40 PM
Passing Parameters to Bash Script mooreted Linux - Software 3 04-05-2004 09:08 PM
passing java parameters to a unix script nephilim Programming 25 10-22-2003 10:51 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 AM.

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