Wednesday, November 16, 2011

Switch/case with regular expressions in Perl

Creating a switch/case in perl with regular expressions are the input, similar to bash' wildcarding.
sub adjusttype {
 my ($record) = @_;
SWITCH: {
  (
        $y[0] =~ /Local/
    or $y[0] =~ /Announc/
  ) && do { $record->{type} = 'Talk'; last SWITCH; };
  ( $y[0] =~ /and answers/ )
   && do { $record->{type} = 'Question and answers'; last SWITCH; };
  ( $y[0] )
   && do {    # strip the type from the title (if exists)
   $record->{title} =~ s/$y[0]//g;
   $record->{type} = $y[0];
   last SWITCH;
   };
 }

Tuesday, November 1, 2011

For Do Loop in Bash as one liner

Take note of the semi-colons ... that is the key

$ for i in {1..35}; do echo $i; done;