For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2004 > Perl Newbie Question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Perl Newbie Question
Perl Mail User

2004-05-18, 3:34 pm

Hello All,

I have a question, I am looking to read the name of the file that I am
passing as an argument to the perl script through the while (<> ) part of
the script.

Example: perl script.pl 1.txt 2.txt 3.txt
Each file has information that I am parsing to put into a report but I need
to get the name of the file that I parsed and print that information as well,
so that way I know what values I am getting from each file associates with
what file.

So the output would look like

1.txt (parsed information)
2.txt (parsed information)
3.txt (parsed information)

Any assistance would be great.
Thanks
James Edward Gray II

2004-05-18, 3:34 pm

On May 18, 2004, at 1:10 PM, Perl Mail User wrote:

> Hello All,
>
> I have a question, I am looking to read the name of the file that I am
> passing as an argument to the perl script through the while (<> ) part
> of
> the script.


You're looking for the $ARGV variable. It contains the filename you
need.

Hope that helps.

James

Bob Showalter

2004-05-18, 3:34 pm

Perl Mail User wrote:
> Hello All,


Hi. Providing a real name would be considered polite. Also, please choose a
meaningful subject.

>
> I have a question, I am looking to read the name of the file that I am
> passing as an argument to the perl script through the while (<> ) part
> of
> the script.


The file name is in $ARGV. see "perldoc perlvar".

If you need to detect when <> switches from one file to another, see the
examples under "perldoc -f eof"

HTH
Paul Johnson

2004-05-18, 3:34 pm

On Tue, May 18, 2004 at 01:10:27PM -0500, Perl Mail User wrote:

> I have a question, I am looking to read the name of the file that I am
> passing as an argument to the perl script through the while (<> ) part of
> the script.


$ARGV

perldoc perlvar

--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com