Hi monks, Once again back with a problem. I am reading from a file in which each line contains staremnet in the form
$step1 1 $step2 1 $step3 1
Now I am ryng to read this file and initialize some variables in my code but the variables are not getting initialized.Some problem is there with my logic..plz help me out..I am writting a sample code for your conviniennce
#!/usr/bin/perl my $step1; my $step2; my $step3; my @array1; my @array; my $i = 0; open(FILE, "assign"); $line = <FILE>; while ($line ne ""){ chomp($line); if($line =~ /^(\S+)\s+(\d+)$/) { print "inside\n"; $hash{$1} = $2; $i++; } $line = <FILE>; } while( ($key, $value) = each %hash) { print "$key +> $value\n"; $key = $value; } if($step1){ print "first\n"; } if($step2) { print "second\n"; } if($step3) { print "thisrd\n"; }
the print statement in the if loops are not getting executed and that where my problem lies

In reply to reading from a file and initializing a variable by s_gaurav1091

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.