Counting characters in perl..
Aug 13, 2010 in Perl
From http://www.perlmonks.org/?node_id=63955
How many ‘a’ characters are in the string?
#!/usr/bin/perl my $str = 'abcatpdmeuziapmb'; my $cnt = @{[$str =~ /(a)/g]}; print "$cnt\n";
Aug 13, 2010 in Perl
From http://www.perlmonks.org/?node_id=63955
How many ‘a’ characters are in the string?
#!/usr/bin/perl my $str = 'abcatpdmeuziapmb'; my $cnt = @{[$str =~ /(a)/g]}; print "$cnt\n";
Oct 09, 2008 in Perl
#!/usr/bin/perl -w use strict; sub showHash($) { my(%hashh) = %{$_[0]}; my($temp); foreach $temp (keys(%hashh)) { print "$temp=" . $hashh{$temp} . "\n"; } print "\n"; } sub higherLevel($) { my(%hashh) = %{$_[0]}; showHash(\%hashh); } my %hash = ("1"=>"one","2"=>"two","3"=>"three"); higherLevel(\%hash);
Oct 09, 2008 in Perl
From http://www.cs.cf.ac.uk/Dave/PERL/node61.html ..
@array1 = (1..5); @array2 = ("A".."E"); firstSub( \@array1, \@array2); # One sub firstSub { my($ref_firstArray, $ref_secondArray) = @_; # Two print("The first array is @{$ref_firstArray}.\n"); # Three print("The second array is @{$ref_secondArray}.\n"); # Three }
Oct 07, 2008 in Perl
#!/usr/bin/perl use strict; { package SomeClass; sub new { my $class = shift; my $self = { v1 => undef, v2 => undef, }; bless($self, $class); return $self; } sub setV1($) { my $self = shift; if (@_) { $self->{v1} = shift } return $self->{v1}; } sub getV1() { my $self = shift; return $self->{v1}; } } main(); sub main() { my $foo = SomeClass->new(); $foo->setV1(38); print $foo->getV1() . "\n"; }
Jul 21, 2008 in Perl
From http://goldenink.com/perl/perldebug.html
perl -w myprogram perl -d myprogram * c (continue) - start program (or continue from breakpoint) * l - lists the next few lines * p [variable name] - print the value of a variable * q - quit. * r - returns from current subroutine * n - executes the next statement at this level * s - The step command - just hit enter to repeat the command. * b - Set a breakpoint - "b n" for line "n", see other conditional breakpoints.