2mths has asked for the wisdom of the Perl Monks concerning the following question:

I'm not sure how to describe my problem so apologies in advance.
I have some software that generates notifications. I want to write a script to take the info (text) generated and 'do' something with it.
I don't know how to 'pull in' the info. I posted to the software list and I've copied an excerpt from the only reply...
"the script just reads from STDIN with a
while (<>) { }
loop, processing line by line.
This is under Solaris but it should work under Windows as well."
Well I don't think it is the same under Windows as this isn't working for me (but I could be being stupid). I've tried variations on this while (<STDIN>){}, @array = <> and @array = <STDIN> (I realise some of these might not be valid syntax) but no joy.
Any pointers appreciated.

Sorry too about the strange formatting

Replies are listed 'Best First'.
Re: How to 'pull in' input
by Zaxo (Archbishop) on Sep 18, 2003 at 16:42 UTC

    I think we need more information about where your info comes from, and what you're trying to do with it. I'm unclear about how your connection is made and to what.

    Does

    while (<>) { chomp; push @array, $_; }
    improve matters? Though if that works, @array = <>; should.

    After Compline,
    Zaxo

Re: How to 'pull in' input
by Paladin (Vicar) on Sep 18, 2003 at 16:37 UTC
    How are you sending the info to the perl script? Reading from <> seems to work fine for me in Windows (ActiveState Perl v5.8.0):
    H:\>echo foobar | perl -le "while (<>) { print qq/Got Line: $_/ } " Got Line: foobar
Re: How to 'pull in' input
by nimdokk (Vicar) on Sep 18, 2003 at 16:43 UTC
    If the information is being put into a file, you can open the file, then using a while loop iterate through it and parse the data the way you want. It would look something like:

    open LOG, "mylogfile.txt" or die "Cannot open file $!"; while (<LOG>) { #do some stuff with data } close LOG;
    This is one way that it could be done. Note, this should work on either Solaris or Windows. I have done this sort of thing on both Unix and Windows. To make sure you are looping through properly, you might try a simple loop like this:
    open LOG, "mylogfile.txt" or die "Cannot open file $!"; while (<LOG>) { print $_; # this will print out the value of $_ so you can # check it to make sure it is what you want to be # processing. } close LOG;

    Hope this helps some.


    "Ex libris un peut de tout"
THANKYOU - How to 'pull in' input
by 2mths (Beadle) on Sep 19, 2003 at 13:37 UTC
    Paladin, Zaxo, nimdokk - Thankyou very much.

    Your posts were informative, helpful and appreciated. + to all.

    I've got the 'thing' working, basically after reading your posts and working through the setup and script again.