Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Modifying pos() from within (?{...})

by tybalt89 (Monsignor)
on Apr 26, 2018 at 12:46 UTC ( [id://1213599]=note: print w/replies, xml ) Need Help??


in reply to Modifying pos() from within (?{...})

A few tweaks.

#!/usr/bin/perl # http://perlmonks.org/?node_id=1213595 use strict; use warnings; use 5.016; our $VERSION = 0.1; # Rebuild PNG image local $/; my $input = <DATA>; chomp $input; $input = pack "H*", $input; # Skip PNG Header $input = substr( $input, 8 ); while ( $input =~ /\G # four byte length (....) # four byte tag (....) # variable length data ((??{ # unpack length my $length = unpack "N", $1; print STDERR "$2 $length\n"; ".{$length}"})) # four byte crc (....)/gcsx ) { my ( $len, $tag, $data, $crc ) = ($1, $2, $3, $4); say "Chunk len:", unpack "N", $len; say "Chunk tag:", $tag; say "Chunk data:", unpack "H*", $data; say "Chunk data len:", length $data; say "Chunk CRC: ", unpack "H*", $crc; } __DATA__ 89504e470d0a1a0a0000000d4948445200000010000000100803000000282d0f530000 +015c504c544547704c4f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7 +eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb5 +4f7eb54f7eb44f7eb54f7eb54f7eb44f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7 +eb54f7eb44f7eb54f7eb54f7eb54f7eb54f7eb44f7eb54f7eb54f7eb34f7eb54f7eb5 +4f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb44f7eb54f7eb44f7 +eb54f7eb54f7eb54f7eb54f7eb44f7eb54f7eb54f7eb54f7eb54f7eb44f7eb54f7eb5 +4f7eb54f7eb54f7eb54f7eb54f7eb54f7eb44f7eb54f7eb54f7eb54f7eb54f7eb54f7 +eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb44f7eb5 +4f7eb54f7eb54f7eb54f7eb34f7eb54f7eb54f7eb54f7eb54f7eb44f7eb54f7eb54f7 +eb44f7eb54f7eb54f7eb44f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb54f7eb4 +4f7eb54f7eb54f7eb5a29b27fc0000007374524e5300242d75280b02fa8bae61fdf7f +bf5e266d109dd6462faf9fc6b0dde6571b3d9b0031f01e0cd83d64505928fc51eb405 +582a426d052f12e5840e63ecea046ab248d0f6327c3e0c4ff311b67960822ef295f8a +093af76e3683c3d7213eb02192cbb8106f190db5ad42cc19ba7504c36150ec28de169 +2647000000cb4944415418d3636040005b264b0614e0e7e50c24f595617ccf201e5f3 +706062e16289f8d39b0d83fc09521980bc237737011e6f370b260080fb11390111195 +55b0b6f7f671b7d2658808e3e665176397282e2e766404298de229860173539040226 +f71b18db43848401eac222db9983d9445925385bb584e0a2490915a1c13c9c0c0aac1 +5fccc10612c8e1e74b8806d28682eacc60fb8b84d3536281b4910ea731588043303b3 +30e481ba8ea690b8104720b05b2e2813413879a96124840282fbf2009c4d034615504 +520015a424be37c5c7be0000000049454e44ae426082

Replies are listed 'Best First'.
Re^2: Modifying pos() from within (?{...})
by mxb (Pilgrim) on Apr 26, 2018 at 13:07 UTC

    Oh! of course! I was returning "(.){$len}", which is $len number of single character capture groups. What I actually wanted was "(.{$len})" - a single capture of length $len.

    I also see you added the missing /s modifier, which explains why it was stopping mid way through.

    That makes the (??{...}) issue much clearer. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2024-04-18 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found