in reply to reg ex help

If you know the separator (white space) you don't have to use a regexp. A simple split will do.
my $line = qq|30 44 02 01 01 04 06 70 75 62 6C 69 63 A7 37 02 0D.....p +ublic.7|; my $fourteenthnumber = (split (/ /, $line))[13]; print $fourteenthnumber;
updated with tachyon's syntactic sugar from /\s/ to / /.

pelagic

Replies are listed 'Best First'.
Re: Re: reg ex help
by tachyon (Chancellor) on Apr 15, 2004 at 10:19 UTC

    FWIW split ' ', $data is magical in that the ' ' matches any quanitity of whitespace ie spaces, tabs, newlines. Syntactic sugar for \s+ really.

    cheers

    tachyon

      FWIW split ' ', $data is magical in that the ' ' matches any quanitity of whitespace ie spaces, tabs, newlines. Syntactic sugar for \s+ really.
      split ' ' and split /\s+/ are not quite the same:
      #!/usr/bin/perl use strict; use warnings; $_ = " foo bar baz "; my @a = split ' '; my @b = split /\s+/; print scalar @a, "\n"; print scalar @b, "\n"; __END__ 3 4

      Abigail

        Thanks for clarifying that ' ' is DWIM (magical) with respect to leading whitespace.

        #!/usr/bin/perl use Data::Dumper; $_ = " foo bar baz "; my @a = split ' '; my @b = split /\s+/; print Dumper \@a; print Dumper \@b; __DATA__ $VAR1 = [ 'foo', 'bar', 'baz' ]; $VAR1 = [ '', 'foo', 'bar', 'baz' ];

        What interests me from a 'why is it so?' point of view is that if \s+ splits at the begining of a string to find the NULL why not at the END as well. Your example documants the behaviour but why is leading whitespace treated differently from trailing whitespace? There is afterall a null string after the trailing whitespace as well.

        cheers

        tachyon