Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Extracting full digits from a range

by davido (Archbishop)
on Aug 03, 2012 at 19:10 UTC ( #985322=note: print w/ replies, xml ) Need Help??

Comment on Re^2: Extracting full digits from a range
Re^3: Extracting full digits from a range
by linuxkid (Sexton) on Aug 04, 2012 at 15:06 UTC

    nope, never do. probably should have mentioned that

    --linuxkid


    imrunningoutofideas.co.cc

      Well here are the problems. First, you can't chomp a filehandle. When you try, you will get the following compile-time error:

      Can't modify <HANDLE> in chomp at mytest.pl line 8, near "<STDIN> ) " Execution of mytest.pl aborted due to compilation errors.

      Let's assume for a minute that you can chomp a filehandle. You're seeking to assign the return value of chomp, which will return the number of input record separators it chomped, not the target string. So if it could compile, it would return 1 (assuming there's a newline at the end of the target line).

      Let's assume that you fixed all that and managed to put 293F into $start, and 2945 into $end. You still have the problem that the .. range operator can only expand ranges composed of non-empty strings that match /^[a-zA-Z]*[0-9]*\z/. So you don't get any auto-incrementing behavior. Your code:

      @array = ( $start .. $end );

      Attempts to use the range operator on a string that is incompatible with its wiring. According to perlop, if the string doesn't match /^[a-zA-Z]*[0-9]*\z/, then only the left operand will be returned. So after we fix the issues in line that chomps a filehandle and returns '1' to split, we're still left with the fact that the range operator won't even work here.

      The simplest solution is to convert those hex strings into numeric values, perform the range expansion, and then convert the expanded range back to a hex representation.


      Dave

        you can't chomp a filehandle

        While that may be true, the example provided was trying to chomp the readline function:

        $ perl -le'my $x = chomp( <STDIN> )' Can't modify <HANDLE> in chomp at -e line 1, at end of line Execution of -e aborted due to compilation errors. $ perl -le'my $x = chomp( readline STDIN )' Can't modify <HANDLE> in chomp at -e line 1, at end of line Execution of -e aborted due to compilation errors.
        (assuming there's a newline at the end of the target line)

        Also, assuming that readline was called in scalar context and not list context.

      Or even better, start testing the s4#$X   stuff   code you post.

      And while you're at it, cross-check your proposed narrative replies against the relevant documentation.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-08-23 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls