Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Problem while Data Extraction

by GrandFather (Sage)
on Dec 04, 2012 at 03:42 UTC ( #1006985=note: print w/replies, xml ) Need Help??

in reply to Problem while Data Extraction

It may be that on my first reading of your node I understood it backwards, in which case the following code is more likely useful:

#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; my @parts = split /(\|[^\|]*\|)/; for my $part (@parts) { if ($part =~ /\|(.*)\|/) { $part = join '', $part =~ /([\da-f]+)/ig; } else { $part = join '', map {sprintf '%02x', ord $_} split '', $p +art; } print $part; } print "\n"; } __DATA__ |30 31 32 33 34| User-Agent|3A|Google|20 20|Desktop


30313233342e64726f70626f782e636f6d 557365722d4167656e743A476f6f676c6520204465736b746f70
True laziness is hard work

Replies are listed 'Best First'.
Re^2: Problem while Data Extraction
by jpvinny28 (Initiate) on Dec 04, 2012 at 04:11 UTC

    Thank You guys.. YOU GUYS ARE AWESOME.. :)

    I improvised your previous code(Although not efficient as yours).. and was able to do it.. THANKS A LOT..

    while (<INFILE>) { chomp($_); my @parts = split /(\|[^\|]*\|)/; for my $part (@parts) { if ($part =~ /\|(.*)\|/) { $part=~s/\|//gi; $part=~ tr/ //ds; print ($part); } else { my $hex = ascii_to_hex($part); print ($hex); } } print("\n"); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006985]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2018-01-21 11:41 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.