ciryon has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks!
I'm investigating a file, matching and extracting interesting stuff. I split the file several times so it's not intact during my operations. Now I want to know the line number where I extracted something. Is it possible to get this without having to use some kind of counter?
An example to illuminate my problem further:
This is one of the regexes I use to store values in a list. Is it at this point possible to get the line number where I got the match? I have the filename as a variable, but when I match $_ isn't the entire file, but a small part of it. Thanks!if(/(\S+)\s+(\d+)/) { $mylist{$1} = $2; }
Update: I read the file with
Newlines aren't important when going through the data.while (<MYFILE>) { $alldata .= $_ ; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Line number in a file
by pelagic (Priest) on Jul 06, 2004 at 08:36 UTC | |
Re: Line number in a file
by davidj (Priest) on Jul 06, 2004 at 09:04 UTC | |
by pelagic (Priest) on Jul 06, 2004 at 09:39 UTC | |
by Anonymous Monk on Jul 07, 2004 at 06:32 UTC | |
by davidj (Priest) on Jul 07, 2004 at 16:51 UTC | |
Re: Line number in a file
by busunsl (Vicar) on Jul 06, 2004 at 08:37 UTC | |
Re: Line number in a file
by edan (Curate) on Jul 06, 2004 at 09:58 UTC | |
Re: Line number in a file
by ysth (Canon) on Jul 06, 2004 at 09:45 UTC | |
Re: Line number in a file
by Jasper (Chaplain) on Jul 06, 2004 at 10:44 UTC | |
Re: Line number in a file
by murugu (Curate) on Jul 06, 2004 at 10:28 UTC |
Back to
Seekers of Perl Wisdom