Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to store multiples lines/records in a array

by ww (Bishop)
on Jun 28, 2013 at 17:38 UTC ( #1041298=note: print w/ replies, xml ) Need Help??


in reply to How to store multiples lines/records in a array

  • Your data fields appear to be tab or space separated which makes splitting on commas somewhat less than optimal.
  • Ln 4 offers us a Filename and a var, $Filename. That's a few short of a dozen, too. In general, such goofs may be the result of re-typing your code in your post. Suggest you use cut'n'paste, instead.
  • $Filename and $line are undeclared.
  • The indentation on your table-building stanza makes it hard to read; not a big deal here, but in a more complex or longer code segment it would be a problem. Similarly, ending each table, tr, & td tag with a newline would make the resultant html more readable.

If you didn't program your executable by toggling in binary, it wasn't really programming!


Comment on Re: How to store multiples lines/records in a array
Select or Download Code
Replies are listed 'Best First'.
Re^2: How to store multiples lines/records in a array
by Perlseeker_1 (Acolyte) on Jun 28, 2013 at 17:48 UTC
    Hi Monks,

    I am reading records from the file and assigning the each record to array using the below code and trying to print each field in table

    data{ my @values; my $table; my $Filename; open (F, "$Filename") || die ("Could not open $Filename!"); while (my $line = <F>) { chomp($line); push (@values,split(',', $line));} close (F); $table .= "<table border=1>"; for (my $i=1;$i<4;$i++) { $table .= "<tr>"; for (my $j=1;$j<7;$j++) { $table .= "<td>$values[$j]</td>";} $table .= "</tr>";} $table .= "</table>";} } my $table = Data(); Email( $table); sub Email { my ( $table) = @_; my $lEmailAddress = 'hem_k24@gmail.com'; my $env = "- $ENV_NAME"; my $msg = MIME::Lite->new( From => $lEmailAddress, To => $lEmailAddress, Cc => $lEmailAddress, Subject => "Test", Type => 'multipart/mixed', ); $msg->attach( Type => 'TEXT/HTML', Data => $table, ); $msg->send; } <p>This is my input</p> <code> ABC_TEK,12,DFE_YJK,24,JKL_GHY,26,LKJ_UYH,29,GHK_YTH,23,GHS_JSF,34, FHK_THE,25,SHJ_TRE,26,HSJ_TEH,39,AHJ_EGH,56,SGH_HEJ,42,HGE_THE,46, HEJ_EJJ,67,JLE_EJK,89,EHJ_EJK,78,EHJ_IKL,68,EHJ_EJK,57,EJH_EKL,69,

    gives me this output message / faulty output: in table

    ABC_TEK 12 DFE_YJK 24 JKL_GHY 26 LKJ_UYH 29 GHK_YTH 23 GHS_JSF 34 FHK_ +THE 25 SHJ_TRE 26 HSJ_TEH 39 AHJ_EGH 56 SGH_HEJ 42 HGE_THE 46 HEJ_EJJ + 67 JLE_EJK 89 EHJ_EJK 78 EHJ_IKL 68 EHJ_EJK 57 EJH_EKL 69

    I'm trying to print the fields in table

      So, so far you appear to have dealt with only half the suggestions I offered/problems I mentioned.

      And, you've changed the specification for the data. I suppose that counts too ...so call it three out of four, although that doesn't entirely account for your handling of the observations/recommendations from other Monasterians, above. Their time and effort on your behalf seems to have been been given short shrift, too.

      But -- at least as far as my notes go -- that's OK. I really wrote the rest solely to occupy myself during a slow period between Lion-baitings and bug hunts.

      : - (

      If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041298]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (18)
As of 2015-07-07 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls