#!/usr/bin/perl
no strict; # Yuk! no warnings; # Yuk! # s/no/use/gsm;
my $step1; my $step2; my $step3; my @array1; my @array; my $i = 0;
open(FILE, "assign");
open my $fh, '<', 'assign' or die "hard, but say why (\$!): $!\n";
$line = <FILE>; while ($line ne ""){
Huh?!? Do you mean to iterate over the lines of your file? If so... the you're not doing it. Just do it the perl idiomatic way:
while (<$fh>) { ... # or while (my $line=<$fh>) { ...
chomp($line); if($line =~ /^(\S+)\s+(\d+)$/) { print "inside\n"; $hash{$1} = $2;
So you are using a hash after all! Then stop here and stick with it!! Don't try useless symref hacking...
$i++;
Am I missing something or are you doing... ehm! nothing, with that self mainteined counter?
while( ($key, $value) = each %hash) { print "$key +> $value\n"; $key = $value; }
Worth repeating: don't! (even if you knew how to do it correctly!)

Proof of concept:

#!/usr/bin/perl -ln use strict; use warnings; BEGIN { @ARGV='assign' } our %hash; $hash{$1}=$2 if /^(\S+)\s+(\d+)/; END { my @msg=qw/FOO 1st 2nd 3rd/; $hash{"\$step$_"} and print $msg[$_] for 1..3; } __END__

In reply to Re: reading from a file and initializing a variable by blazar
in thread 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.