Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

You print $line->[0] which is quite different from $line[0]. How this prints "371225..." is beyond me.

You also do lots of strange things to my eye, but that is to be expected ;-). For example to copy @arr into @line (for which you used a loop) "@arr= @line;" would have been enough. The same goes for "my @lines= ($line[0]..."

Also using lots of variables called $line, $lines, @line, @lines makes any program into an entry into the obfuscation contest. Differentiate your variables better

What you have been looking for might be this:

# starting with @arr having all the lines my @ticker; my @names=('ticket','dateadded','stime','etime','pri','SiteName','comm +ents'); my $i=0; foreach my $line (@arr) { my @items= split(/\|/, $line; print "ETime is $items[3]\n"; $ticker[$i]{$names{$_}}= $items[$_] for scalar @names; $i++; } # now $ticker[3]{SiteName} is SiteName of the fourth line

Note @ticker and $i are only neccessary if you want to operate on the data after the loop. If you just want to print or store the stuff, do that in the foreach loop above. You can also just use the split line you have in your script to fill the variables with the data inside the loop instead of using @items if it suits you better


In reply to Re: Spliting a delimited string into variables by jethro
in thread Spliting a delimited string into variables by pissflaps

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-20 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found