Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I think I need to clarify what is is I doing with this file because trying what you suggested did not work. this is the data: date|time|node|num|warning|error I am trying to use @DATA_IN=split(/\|/,$_); with in a while loop but it won't let me. I have completely misinterpretted what you suggested.....

Replies are listed 'Best First'.
Re: pipe as a delimiter II
by chromatic (Archbishop) on May 15, 2001 at 02:36 UTC
    If you're using 5.005 or earlier, you have to ask "Mother may I?". If you're using Perl 5.6 or later, you have to wait until you hear "Perl says..."

    Seriously, we can only guess at what's going on when you say "won't let me". You'll need to post more code.

    If I were you, I'd have something like:

    open(INPUT, 'file.txt') or die "Can't open file.txt: $!"; while (<INPUT>) { chomp; my @data = split(/\|/, $_); # do something with @data } close INPUT;
    Untested code, because I've done that at least twice before. :)

    Please reply to this post (or another in this thread) with any information that can help to clarify.

Re: pipe as a delimiter II
by arturo (Vicar) on May 15, 2001 at 02:39 UTC

    That should be working, assuming I understand you correctly. Are you sure $_ has been set? What do you mean by "it won't let me"?

    It would help us more if you would post your code. Be sure to use <code> and </code> tags when you do, and don't bother creating a new node. Just reply to the node you've posted here.

    Skeletal code that should work:

    open FILE, $filename or die "Can't open $filename: $!\n"; while (<FILE>) { my @data_in = split /\|/, $_; # process @data_in }
    perl -e 'print "How sweet does a rose smell? "; chomp $n = <STDIN>; $r +ose = "smells sweet to degree $n"; *other_name = *rose; print "$other +_name\n"'