At 11:52 AM 9/20/01 +1000, Brett Hales wrote:
>Hi,
>
>I am a perl newbie..
>
>I am sending a Perl script about five lines of data via <STDIN>.
>
>cat filename | ./my_perl_script.pl
>
>Where filename contains
>
>This is line one sending to perl
>this is line two with DATE: 19-Sept-01 and
>I want to grab a certain string
>and some more here.
>
>I am storing this data like this...
>
>@line=<STDIN>
>
>I think this is working fine.
>
>I now want to grab words from this @line.

It's generally more readable to name arrays in the plural, e.g., @lines.

>a) I want to know how I can grab a word that is six places in from the 
>left on line 3....in the above example the word would be "certain". I can 
>do this in shell with "awk {print $6}"... Is there something with perl?

(split /\s+/, $line[2])[5]

>b) I want to find a regexp eg I want the DATE string...how can I find this.

@dates = map /DATE:\s+(\S+)/, @line

>I have thought about how I can cycle through the @line array and how I can 
>extract the data....not sure if I should be getting rid of all the returns 
>and placing it in one string.

Depends entirely on what you're doing.  In general, it's better to process 
a line at a time looking for what you want.

The questions you're asking are almost certainly based upon incorrect 
assumptions about the best way to do what you want.  Try backing up a bit 
and you may get more useful answers.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to