hello, i've checked many sites for examples and am amazed that i can't find a simple example of an if statement to test for an alphanumber value ie: if($key == "a" )
to run this pgm: perl del3.pl delin
delin data is:
a=1
b=2
c=3
thanks for any pointers
ps: java programmer trying to learn PERL!
#!/usr/bin/perl -w
die "Usage: scanmegadata <data file> <site name>\n"
unless @ARGV == 1;
my $megalithFile = $ARGV[0];
open MEGADATA, "<$megalithFile"
or die "Can't open $megalithFile: $!\n";
my ( $key, $value );
my %hash = ();
while ( <MEGADATA> ) {
chop;
( $key, $value ) = split( /=/, $_ );
$hash{$key} = $value;
}
while ( my ($key, $value) = each(%hash) ) {
if($key == "a" )
{
#print "$key => $value\n";
}
}
for my $key ( keys %hash ) {
my $value = $hash{$key};
if($value==1)
{
print "$key => $value\n";
}
}
close MEGADATA;
exit 9;
to run this pgm: perl del3.pl delin
delin data is:
a=1
b=2
c=3
thanks for any pointers
ps: java programmer trying to learn PERL!
#!/usr/bin/perl -w
die "Usage: scanmegadata <data file> <site name>\n"
unless @ARGV == 1;
my $megalithFile = $ARGV[0];
open MEGADATA, "<$megalithFile"
or die "Can't open $megalithFile: $!\n";
my ( $key, $value );
my %hash = ();
while ( <MEGADATA> ) {
chop;
( $key, $value ) = split( /=/, $_ );
$hash{$key} = $value;
}
while ( my ($key, $value) = each(%hash) ) {
if($key == "a" )
{
#print "$key => $value\n";
}
}
for my $key ( keys %hash ) {
my $value = $hash{$key};
if($value==1)
{
print "$key => $value\n";
}
}
close MEGADATA;
exit 9;