in reply to Simple but not elegant ?

that is ugly

I would do something like this.

#!perl use strict; foreach my $line (<DATA>){ if ( $line =~ /\bH00(.*)$/ ) { # print " hoo $1 \n"; } elsif ( $line =~ /\bH01(.*)$/ ) { # print " ho1 $1 \n"; } elsif ( $line =~ /\bD0(.*)$/ ) { # print " do1 $1 \n"; } } __DATA__ H00 Header1 H01 Header2 D01 data1 D02 data2

Replies are listed 'Best First'.
Re^2: Simple but not elegant ?
by Anonymous Monk on Jun 01, 2015 at 18:41 UTC
    that is ugly

    And some people think if-elsif chains and blocks without indentation are ugly...

    What does your code do with a line like "H01 H00"?