What is the equivalent hash function of "push' arrays in perl? -
i beginner programmer writing program using perl allow me search name, , have tell me steps. far (with of many nice people on here) have code array format.
#!/usr/local/bin/perl use strict; use warnings; @m_array; @f_array; open (my $input, "<", 'ssbn1898.txt'); while ( <$input> ) { chomp; ( $name, $id ) = split ( /,/ ); if ( $id eq "m" ) { push ( @m_array, $name ); } else { push ( @f_array, $name ); } } close ( $input ); print 'm: ' . join("\t", @m_array) . "\n"; print 'f: ' . join("\t", @f_array) . "\n"; and attempted use same code put hash.
#!/usr/local/bin/perl use strict; use warnings; %m_hash; %f_hash; open (my $input, "<", 'ssbn1898.txt'); while ( <$input> ) { chomp; ( $name, $id ) = split ( /,/ ); if ( $id eq "m" ) { push ( %m_hash, $name ); } else { push ( %f_hash, $name ); } } close ( $input ); print 'm: ' . join("\t", %m_hash) . "\n"; print 'f: ' . join("\t", %f_hash) . "\n"; but error on "push" function. assume function arrays. there equivalent function hash? , "push" function do? thank
http://www.ourbabynamer.com/popular-baby-names.php?year=1898&top=1000&country=us&order=0&page=1 data working
push adds element of array.
@a = ( 1, 2, 3 ); push @a, 4; # @a ( 1, 2, 3, 4 ) insert adds element hash.
%h = ( foo => 1, bar => 2 ); $h{ qux } = 3; # %h ( foo => 1, bar => 2, qux => 3 ); take @ perldoc perlintro
Comments
Post a Comment