Re: [ILUG] OT perl Q

From: Fergal Daly (fergal at domain esatclear.ie)
Date: Fri 10 Aug 2001 - 13:10:31 IST


rewritten a little

my at domain chars = split //, $buf; # split $buf into an array of individual chars

my at domain hexes = map { ord($_) } at domain chars; # coverts each char to it's ASCII value

foreach ( at domain hexes)
...

map takes an array in one side, does something to the elements of the array
one at a time and fires the resulting array out the other side. Another way
to do this would be

my at domain hexes;

foreach my $elem ( at domain chars)
{
        push( at domain hexes, ord($elem)
}

Fergal

On Fri, Aug 10, 2001 at 12:32:49PM +0100, JustinMacCarthy wrote:
> Hi all, I'm just writting a perl script to dump a file in HEX I came across
> this, which does what I want but can someone explain this line to me ? or
> write it differently ?
>
> for(map ord, split // , $buf)
>
> Thanks
>
> ~J
>
> $file = $ARGV[0];
> open (FILE, $file) or die "Can't open file";
> while ( read (FILE , $buf , 1024) )
> {
> for(map ord, split // , $buf)
> {
> printf "%02x ",$_;
> }
> }
> close (FILE);
>
>
> --
> Irish Linux Users' Group: ilug at domain linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at domain linux.ie

-- 


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:11:32 GMT