Perl References/Dereferences

An enumerated or comma-separated list always returns the last element in a scalar context. An array reference is created by either: * the [ ] operator around a list * the operator in front of a list variable (@) A hash reference is created by either: * the { } operator around a list (of pairs) * the operator in front of a hash variable (%) Example Code: ############################################################# references.pl #!/usr/bin/perl -w use strict; use Data::Dumper; my @a = qw( hello there you guys ); # a regular array my %grade = qw( A 4.0 B 3.1 C 2.0 D […]

Read more

Reading a File via Perl Script

Reading with <> into an array: gets lines into array as is in file along with new line chars. each $line_$i in file = $arr[$i] Reading with <> into hash : sets $has{$key} = $value. where $key = line_$i and $value = line_$i+1 respectively. < p>Reading with <> using while loop: gets each line along with "n" chars

Read more

Perl System Command and Return Codes

Many of you must have used Perl as part of day to day automation. Some teams use test harnesses made exclusively of Perl. This makes it easier to leverage various functionalitiesof text manipulation, file operations and process monitoring, etc which is needed for a functional test harness. More often, system command is used to run an executable and its return code ($?) is used to compare with expected return code. Normally, a successs means value of $? is zero and failure if otherwise. This is good if you plan to write tests from scratch and team decides to go with […]

Read more