[25416] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7661 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 17 14:05:38 2005

Date: Mon, 17 Jan 2005 11:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 17 Jan 2005     Volume: 10 Number: 7661

Today's topics:
    Re: [newbie] chomp acting weird (or me not understandin <hendrik_maryns@despammed.com>
    Re: [newbie] chomp acting weird (or me not understandin <hendrik_maryns@despammed.com>
    Re: [perl-python] 20050116 defining a function <xah@xahlee.org>
    Re: [perl-python] 20050117, filter, map <xah@xahlee.org>
    Re: [perl-python] 20050117, filter, map <xah@xahlee.org>
    Re: Closing Excel <jimsimpson@cox.net>
        creating socket on specific IP address <alex_the_hart@yahoo.com>
        How to compare files? <no@no.no>
    Re: How to compare files? <news@chaos-net.de>
    Re: How to compare files? <tony_curtis32@yahoo.com>
    Re: How to compare files? <ccolumbu@hotmail.com>
    Re: installing module to my own directory with MCPAN ioneabu@yahoo.com
        Introducing a character in a string (Arun Kumar)
    Re: Introducing a character in a string <josef.moellers@fujitsu-siemens.com>
    Re: Introducing a character in a string <mritty@gmail.com>
    Re: Low level data manipulation in Perl <perl@lennychallis.co.uk>
    Re: Low level data manipulation in Perl xhoster@gmail.com
    Re: Low level data manipulation in Perl (Anno Siegel)
    Re: Low level data manipulation in Perl <1usa@llenroc.ude.invalid>
    Re: Low level data manipulation in Perl <perl@lennychallis.co.uk>
    Re: Low level data manipulation in Perl <perl@lennychallis.co.uk>
    Re: Low level data manipulation in Perl <1usa@llenroc.ude.invalid>
    Re: Low level data manipulation in Perl <jl_post@hotmail.com>
        MAP Question <georgekinley@hotmail.com>
    Re: MAP Question <perl@my-header.org>
    Re: MAP Question (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 17 Jan 2005 16:53:03 +0100
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <weOdndeIT7nDQnbcRVnygQ@scarlet.biz>

Michele Dondi schreef:

> On Sun, 16 Jan 2005 23:10:10 +0100, Hendrik Maryns
> <hendrik_maryns@despammed.com> wrote:
> 
> 
>>>>#add this when testing
>>>>open(INFILE, "test.txt");
> 
> [snip]
> 
>>>  open my $in, '<', 'test.txt' or die $!
>>>
>>>takes only a few more keystrokes.
>>
>>Uh, ok, but as I don't even understand what this does, you can't expect 
>>me to type it...  I'll study the docs.
> 
> 
> It doesn't do anything much different from what your statement did.
> Only it uses a lexical filehandle, that you can use later just like
> any other filehandle e.g. like
>   
>   while (<$in>) { #...
> 
> and it separately specifies the open() mode, i.e. 'for reading', even
> if this wouldn't be strictly necessary (but IMHO is a good practice).
> Oh, and last but not least it prints a minimal but descriptive error
> message if anything goes wrong.

Interesting & very useful, thanks.

>>>Please note that this doesn't _strictly_ match the description above
>>>(not that it matters, IMHO). Also, it _seems_ that '.' in the first
>>>field ends a sentence just as much 'LET()' in the second one does.
>>
>>It does, but sometimes, it is not '.' but '?' or '...', whereas there 
>>will always be 'LET()' in the second column.
> 
> 
> Hmm, this is one of those cases in which I would like to have Perl6's
> junctions ready. (Yes: I know there are already suitable modules,
> etc.)
> 
> Alternatively you can use a regex, e.g.
> 
>   /^(?:\.|\Q...\E|\?)$/
> 
> but I agree that it's better to whatch the second field. So a possible
> solution can be
> 
> 
>   #!/usr/bin/perl -ln
>   
>   use strict;
>   use warnings;
>   
>   our @w;
>   my ($w,$c)=split;
>   print("@w$w"), @w=(), next
>     if $c eq 'LET()';
>   push @w, $w;
>   
>   __END__
> 
> 
> Please note that just as much as the similar code pasted in my
> previous post, this is meant to be a minimal working example. Unless
> you need only a quick hack in a realistic app you'd probably
> explicitly write the loop and add bells and whistles...

I think I will, as I don't think my professor will believe I wrote this 
myself...

Thanks!
H.


------------------------------

Date: Mon, 17 Jan 2005 16:56:21 +0100
From: Hendrik Maryns <hendrik_maryns@despammed.com>
Subject: Re: [newbie] chomp acting weird (or me not understanding how it works??)
Message-Id: <weOdndaIT7m5fXbcRVnygQ@scarlet.biz>

Arndt Jonasson schreef:

> Hendrik Maryns <hendrik_maryns@despammed.com> writes:
> 
>># test.pl (not on Unix, so no /user/bin/perl?)
>>use warnings;
>>use strict;
>>open(INFILE, "test.txt")||die("open didn't succeed");
>>my @zinwoorden;
>>do{
>>     chomp(my $lijn=<INFILE>);
>>     while ($lijn!~/LET/){
>>         push(@zinwoorden,$lijn);
>>         $lijn=<INFILE>;
>>     } #enduntil
>>     for (@zinwoorden){
>>         s/(\w+).*/$1/;
>>     }
>>     my $zin=join (" ", @zinwoorden);
>>     print "$zin \n";
>>} until eof(INFILE);
> 
> 
> As someone already told you in the first response to your original
> question, you need to chomp all lines you read:
> 
>       while ($lijn!~/LET/){
>           push(@zinwoorden,$lijn);
>           chomp($lijn=<INFILE>);
>       } #enduntil

How stupid of me, of course!
I'm ashamed to have bothered you for such a triviality, sorry for that.
Thanks, H.


------------------------------

Date: 17 Jan 2005 09:38:36 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: Re: [perl-python] 20050116 defining a function
Message-Id: <1105983516.736238.314050@f14g2000cwb.googlegroups.com>

errata:

* the variables in the perl section should be declared inside the
subroutine.
* the @_[0] should've been $_[0]

thanks for Dave Cross for pointing them out.

* the Mathematica Apply should be Select...
Xah
 xah@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html



------------------------------

Date: 17 Jan 2005 09:43:19 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: Re: [perl-python] 20050117, filter, map
Message-Id: <1105983799.202346.9710@f14g2000cwb.googlegroups.com>

erratum:

the Mathematica Apply should've been Select.
 ...

 Xah
 xah@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html



------------------------------

Date: 17 Jan 2005 09:45:01 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: Re: [perl-python] 20050117, filter, map
Message-Id: <1105983901.353590.83310@c13g2000cwb.googlegroups.com>

erratum:

the Mathematica Apply should've been Select.
 ...

 Xah
 xah@xahlee.org
 http://xahlee.org/PageTwo_dir/more.html



------------------------------

Date: Mon, 17 Jan 2005 09:44:31 -0500
From: "jim simpson" <jimsimpson@cox.net>
Subject: Re: Closing Excel
Message-Id: <SbQGd.77817$Jk5.8129@lakeread01>

Thanks to all who responded to my Post.

It works great, of course, and I do need Bob's addition.

Jim


"Jay Tilton" <tiltonj@erols.com> wrote in message
news:41eadcff.63134402@news.erols.com...
> "jim simpson" <jimsimpson@cox.net> wrote:
>
> : I need to determine if Excel is running and if so close it. Can this be
done
> : with a Perl script and can someone suggest an approach to do it.
>
>     #!perl
>     use warnings;
>     use strict;
>     use Win32::OLE;
>
>     while(
>         my $excel =
>         Win32::OLE ->GetActiveObject('Excel.Application')
>     ) {
>         $excel ->Quit
>     }
>




------------------------------

Date: 17 Jan 2005 10:44:01 -0800
From: "Al the Pal" <alex_the_hart@yahoo.com>
Subject: creating socket on specific IP address
Message-Id: <1105987441.825760.263220@z14g2000cwz.googlegroups.com>

I'm sorry if this is a repost. I thought I posted this, but don't see
it on the board, so I'll try again.

Hi Geniuses,

Probably an easy one, but I can't find the answer.

I have a server with several IP addresses, and when I make a socket, I
want control over which IP address I connect from.

Right now I use this:

my $iaddr = Socket::inet_aton($server) || return 0;
my $paddr = Socket::sockaddr_in($port, $iaddr) || return 0;
my $proto = getprotobyname('tcp');
socket(TCP, Socket::PF_INET, Socket::SOCK_STREAM, $proto) || return 0;
connect(TCP, $paddr) || return 0;

How can I make this code force the local IP address to what I want?
Thanks in advance.

- Alex



------------------------------

Date: Mon, 17 Jan 2005 18:46:02 +0100
From: Case <no@no.no>
Subject: How to compare files?
Message-Id: <41ebfb23$0$6221$e4fe514c@news.xs4all.nl>

What is a good (readable) way of comparing two
files.  I just need to know if they match, or not.

Thanks,

Case



------------------------------

Date: 17 Jan 2005 17:56:50 GMT
From: Martin Kissner <news@chaos-net.de>
Subject: Re: How to compare files?
Message-Id: <slrncunv33.gsr.news@maki.homeunix.net>

Case wrote :
> What is a good (readable) way of comparing two
> files.  I just need to know if they match, or not.

since seem to be on Linux, you might use "diff"
diff file1 file2
diff -y file1 file2
if you want to use the side by side output format.

HTH

-- 
Epur Si Muove (Gallileo Gallilei)


------------------------------

Date: Mon, 17 Jan 2005 12:00:27 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to compare files?
Message-Id: <87oefodjgk.fsf@limey.hpcc.uh.edu>

>> On Mon, 17 Jan 2005 18:46:02 +0100,
>> Case <no@no.no> said:

> What is a good (readable) way of comparing two files.  I
> just need to know if they match, or not.

http://search.cpan.org/ and search for "diff".

Text::Diff is probably what you want.


------------------------------

Date: Mon, 17 Jan 2005 10:21:24 -0800
From: "Chad Columbus" <ccolumbu@hotmail.com>
Subject: Re: How to compare files?
Message-Id: <jmTGd.581$Nu.230@fed1read04>

use File::Compare;
Is probably better for what you want.

-- 

Chad

"Case" <no@no.no> wrote in message 
news:41ebfb23$0$6221$e4fe514c@news.xs4all.nl...
> What is a good (readable) way of comparing two
> files.  I just need to know if they match, or not.
>
> Thanks,
>
> Case
> 



------------------------------

Date: 17 Jan 2005 08:55:34 -0800
From: ioneabu@yahoo.com
Subject: Re: installing module to my own directory with MCPAN
Message-Id: <1105980934.433401.97630@z14g2000cwz.googlegroups.com>


Paul Lalli wrote:
> ioneabu@yahoo.com wrote:
> > [...]
> > > There is nothing called MCPAN.
> >
> > Sorry, I really did not know that the interactive shell for
> downloading
> > modules was actually CPAN.pm.  That is really helpful.  Now that I
> know
> > what I'm using, I'll read about it.  I'm glad that it's not really
> > MCPAN.  It sounds like a McDonald's breakfast.  Thanks!
>
> The -M in
> perl -MCPAN -e'shell'
> is a command line option that loads a module.  Saying -MCPAN is the
> equivalent of saying
> use CPAN;
> within a script.  Read more about it in
> perldoc perlrun
>
> Paul Lalli


Thanks!

I finally got things working, though it took a little experimentation.
The following may be helpful as it worked for me:

create this path and file:

~/.cpan/CPAN/MyConfig.pm

Then put the following in the file:


$home = $ENV{'HOME'};
$CPAN::Config = {
cpan_home=>$home
};
1;
__END__

then type the usual:

perl -MCPAN -e shell

and answer all of the questions.

Look out for the one about PREFIX= so you can let it know where you
want your modules to go.
The contents of the MyConfig.pm gave me the most trouble.

wana



------------------------------

Date: 17 Jan 2005 06:38:27 -0800
From: smsabu2002@yahoo.com (Arun Kumar)
Subject: Introducing a character in a string
Message-Id: <84afc8e.0501170638.2510790d@posting.google.com>

Hi,

  I want to introduce a special character ( \ ) in a string using perl script.
(i.e) "first.last@mail.com" has to be converted into "first.last\@mail.com". 
Please help me. 

Regards,
Arunkumar


------------------------------

Date: Mon, 17 Jan 2005 15:54:10 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Introducing a character in a string
Message-Id: <csgjb2$h0a$1@nntp.fujitsu-siemens.com>

Arun Kumar wrote:
> Hi,
>=20
>   I want to introduce a special character ( \ ) in a string using perl =
script.
> (i.e) "first.last@mail.com" has to be converted into "first.last\@mail.=
com".=20
> Please help me.=20

The answer depends upon the question:
Why would you need it?

If you need it because perl complains about "Possible unintended=20
interpolation of @mail in string", then just insert the backslash=20
character using your favorite editor.

If you _think_ you need the backslash because the @ is a special=20
character and you _think_ that perl might get confused: it won't. If you =

read "first.last@mail.com" from some place (e.g. STDIN, some file), then =

the @ won't be regarded as a special character any more. Introducing a=20
backslash will only introduce one more character, a character you don't=20
really want.

If you still are convonced you need the backslash:

$s =3D 'first.last@mail.com';
$s =3D~ s/\@/\\$&/;

HTH,

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



------------------------------

Date: Mon, 17 Jan 2005 14:50:18 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Introducing a character in a string
Message-Id: <KgQGd.3910$hC2.3312@trndny04>

"Arun Kumar" <smsabu2002@yahoo.com> wrote in message
news:84afc8e.0501170638.2510790d@posting.google.com...
>   I want to introduce a special character ( \ ) in a string using perl
script.
> (i.e) "first.last@mail.com" has to be converted into
"first.last\@mail.com".
> Please help me.

Have you read any documentation or tutorials about regular expressions?
That would be a very good place to start:

perldoc perlretut

Specifically, you want to use the search-and-replace operators s///.

If you have read it and understand regular expressions, please post a
short but complete piece of code demonstrating what you've tried so far
and how it has failed to function as you'd like it to.

Paul Lalli



------------------------------

Date: Mon, 17 Jan 2005 16:43:42 -0000
From: "Leonard Challis" <perl@lennychallis.co.uk>
Subject: Re: Low level data manipulation in Perl
Message-Id: <csgpvs$q6d$1@newsg4.svr.pol.co.uk>

What I am saying is this: Is there any way of opening a file, and instead of
getting the text in side it, you actually see the 1s and0s or the
hexnumbers?

This would then allow me to use the bitwise operators etc to manipulate it.

If there isn't, what would anyone suggest trying? For instance, could i
convert the ascii data i receive in to hex or binary. I'm guessing it isn't
just a simple case of converting it back right?

Thanks for any tips or hints, even a book to read :)
Cheers,


Lenny



"Gregory Toomey" <nospam@bigpond.com> wrote in message 
news:34vgr5F4flkv8U1@individual.net...
> Leonard Challis wrote:
>
>> Hi everyone,
>>
>> I have spent a few hours looking on Google, Perl.com, CPAN etc to try 
>> find
>> some information on messing about with low leveldata in Perl. I am 
>> talking
>> about opening files and looking at them in their very simplest format, 1s
>> and 0s.
>>
>> What I have noticed from my searches so far is things like pack(),
>> unpack(), binmode() and some other stuff, but not really what I'm looking
>> for, AFAIK.
>>
>> If anyone could even just point me in the right direction, maybe just the
>> proper keywords to use in google to find some articles and tutorials on
>> this kind of task in Perl I would much appreciate it.
>>
>> Thanks a lot,
>> Lenny Challis
>
> Pack/unpack easily translate to hexadecimal, and conversion to binary from
> there is trivial.
>
> But Perl has the full complement of bit twiddling operators anyway 
> (similar
> to C).
>
> gtoomey 




------------------------------

Date: 17 Jan 2005 17:15:29 GMT
From: xhoster@gmail.com
Subject: Re: Low level data manipulation in Perl
Message-Id: <20050117121529.857$fk@newsreader.com>

"Leonard Challis" <perl@lennychallis.co.uk> wrote:
> What I am saying is this: Is there any way of opening a file, and instead
> of getting the text in side it, you actually see the 1s and0s or the
> hexnumbers?

The text is identical to the 1 and 0s.  I highly doubt that you are able
to stare at a CPU and "see" the insides of the Perl and perl programs.  So
what you see is not what is inside perl, but rather what you told Perl to
print to your monitor.  If you want to see 1s and 0s, then tell Perl to
print them as 1s and 0s.

> This would then allow me to use the bitwise operators etc to manipulate
> it.

Why don't you read the docs on those bitwise operators?

> If there isn't, what would anyone suggest trying? For instance, could i
> convert the ascii data i receive in to hex or binary. I'm guessing it
> isn't just a simple case of converting it back right?
>
> Thanks for any tips or hints, even a book to read :)

I think you've already been given those tips and hints.  Please, go
followup on them.  After you read all of perlop and all of perlfunc, if
you don't understand, come back and ask specific questions about the
operators and functions you don't understand.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 17 Jan 2005 17:27:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Low level data manipulation in Perl
Message-Id: <csgsih$t3v$1@mamenchi.zrz.TU-Berlin.DE>

Leonard Challis <perl@lennychallis.co.uk> wrote in comp.lang.perl.misc:
> What I am saying is this: Is there any way of opening a file, and instead of
> getting the text in side it, you actually see the 1s and0s or the
> hexnumbers?

The text *is* the ones and zeroes, it's just a matter of interpretation.
To access individual bits, use vec() (perldoc -f vec).

> This would then allow me to use the bitwise operators etc to manipulate it.

What is stopping you?

Here is an example: Compare the strings "a" and "A" bitwise and show the
bit number(s) where they differ:

    my ( $lower, $upper) = ( 'a', 'A');
    for ( 0 .. 7 ) { # eight bits
        print "bits $_ differ\n" if vec( $lower, $_, 1) != vec( $upper, $_, 1);
    }

For ASCII code, that prints "bits 5 differ".  Check with an ASCII table.

Anno


------------------------------

Date: 17 Jan 2005 17:36:22 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Low level data manipulation in Perl
Message-Id: <Xns95E18040A8E67asu1cornelledu@132.236.56.8>

"Leonard Challis" <perl@lennychallis.co.uk> wrote in
news:csgpvs$q6d$1@newsg4.svr.pol.co.uk: 

[ Please do not top-post. If you do not know what that means, and even if 
you do, please read the posting guidelines for this group. ]

> What I am saying is this: Is there any way of opening a file, and
> instead of getting the text in side it, you actually see the 1s and0s
> or the hexnumbers?
> 
> This would then allow me to use the bitwise operators etc to
> manipulate it. 

You are misguided.

See

perldoc perlop

Sinan.


------------------------------

Date: Mon, 17 Jan 2005 18:19:49 -0000
From: "Leonard Challis" <perl@lennychallis.co.uk>
Subject: Re: Low level data manipulation in Perl
Message-Id: <csgvju$413$1@newsg4.svr.pol.co.uk>

You don'tseem to get me straight...

> "Leonard Challis" <perl@lennychallis.co.uk> wrote:
>> What I am saying is this: Is there any way of opening a file, and instead
>> of getting the text in side it, you actually see the 1s and0s or the
>> hexnumbers?

> The text is identical to the 1 and 0s.  I highly doubt that you are able
> to stare at a CPU and "see" the insides of the Perl and perl programs.  So
> what you see is not what is inside perl, but rather what you told Perl to
> print to your monitor.  If you want to see 1s and 0s, then tell Perl to
> print them as 1s and 0s.

I don't want to look at perl's code, I just want to see the file I open. Say 
for instance I have an image and I open it in a HEX editor, I see the binary 
or hex as well as the text for that file. I was wondering if there was any 
way of opening the file and inputting it in this format instead of doing a 
lot of converting. I know you can convert stuff, google has plenty of stuff.

>> This would then allow me to use the bitwise operators etc to manipulate
>> it.
>
> Why don't you read the docs on those bitwise operators?

I know, i was just stating thats what I was planning on doing so you had 
more information. I have been reading up on them.

>
>> If there isn't, what would anyone suggest trying? For instance, could i
>> convert the ascii data i receive in to hex or binary. I'm guessing it
>> isn't just a simple case of converting it back right?
>>
>> Thanks for any tips or hints, even a book to read :)
>
> I think you've already been given those tips and hints.  Please, go
> followup on them.  After you read all of perlop and all of perlfunc, if
> you don't understand, come back and ask specific questions about the
> operators and functions you don't understand.

I have been toldabout conversion to hex/binary and about bitwise operators.. 
NOT about opening a file and inputting in this format straight away. If you 
don'thave an answer I don't mind, don't moan.

Lenny Challis 




------------------------------

Date: Mon, 17 Jan 2005 18:21:50 -0000
From: "Leonard Challis" <perl@lennychallis.co.uk>
Subject: Re: Low level data manipulation in Perl
Message-Id: <csgvnn$evn$1@newsg2.svr.pol.co.uk>

Awesome.

This is exactly what I have been wondering, whether converting from the 
ASCII representation would give me what it is in Binary/HEXetc, and I have 
been reading about vec() too, it's pretty cool!

Thanks alot for your example,
Lenny Challis

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message 
news:csgsih$t3v$1@mamenchi.zrz.TU-Berlin.DE...
> Leonard Challis <perl@lennychallis.co.uk> wrote in comp.lang.perl.misc:
>> What I am saying is this: Is there any way of opening a file, and instead 
>> of
>> getting the text in side it, you actually see the 1s and0s or the
>> hexnumbers?
>
> The text *is* the ones and zeroes, it's just a matter of interpretation.
> To access individual bits, use vec() (perldoc -f vec).
>
>> This would then allow me to use the bitwise operators etc to manipulate 
>> it.
>
> What is stopping you?
>
> Here is an example: Compare the strings "a" and "A" bitwise and show the
> bit number(s) where they differ:
>
>    my ( $lower, $upper) = ( 'a', 'A');
>    for ( 0 .. 7 ) { # eight bits
>        print "bits $_ differ\n" if vec( $lower, $_, 1) != vec( $upper, $_, 
> 1);
>    }
>
> For ASCII code, that prints "bits 5 differ".  Check with an ASCII table.
>
> Anno 




------------------------------

Date: 17 Jan 2005 18:57:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Low level data manipulation in Perl
Message-Id: <Xns95E18DFFE4D97asu1cornelledu@132.236.56.8>

"Leonard Challis" <perl@lennychallis.co.uk> wrote in
news:csgvju$413$1@newsg4.svr.pol.co.uk: 

>> "Leonard Challis" <perl@lennychallis.co.uk> wrote:
>>> What I am saying is this: Is there any way of opening a file, and
>>> instead of getting the text in side it, you actually see the 1s
>>> and0s or the hexnumbers?

 ...

> I have been toldabout conversion to hex/binary and about bitwise
> operators.. NOT about opening a file and inputting in this format
> straight away. If you don'thave an answer I don't mind, don't moan.

WTF are you talking about? There is no excuse for the problem 
description above unless you are six years old.

#! /usr/bin/perl

use strict;
use warnings;

use File::Slurp;

my $file = shift or die "Provide an input file name.\n";
my $contents = read_file($file, binmode => ':raw');

use constant CHUNK_SIZE => 0x10;

my $pos  = 0;
my $last = length $contents;

while($pos + CHUNK_SIZE < $last) {
    print hexdump_line(substr $contents, $pos, CHUNK_SIZE);
    $pos += CHUNK_SIZE;
}

print hexdump_line(substr $contents, $pos, $last - $pos) if($pos < 
$last);

sub hexdump_line {
    my ($row) = @_;
    my @bytes = split '', $row;
    my $output;
    $output .= sprintf '%2.2X', ord($_) for @bytes;
    $row =~ s/[^\x20-\x7e]/\./g;
    $output .= "\t$row\n";
}
__END__

C:\Home> 050117-b.pl 050117-b.pl
2321202F7573722F62696E2F7065726C        #! /usr/bin/perl
0D0A0D0A757365207374726963743B0D        ....use strict;.
0A757365207761726E696E67733B0D0A        .use warnings;..
0D0A7573652046696C653A3A536C7572        ..use File::Slur
703B0D0A0D0A6D79202466696C65203D        p;....my $file =

Sinan


------------------------------

Date: 17 Jan 2005 10:59:58 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Low level data manipulation in Perl
Message-Id: <1105988398.077624.85010@c13g2000cwb.googlegroups.com>

Leonard Challis wrote:
>
> I have spent a few hours looking on Google, Perl.com,
> CPAN etc to try find some information on messing about
> with low leveldata in Perl. I am talking about opening
> files and looking at them in their very simplest format,
> 1s and 0s.


I do a lot of work with binary files.  Sometimes I need to find the
value of a specific bit in a binary file.  Here is how to convert a
binary file into its binary 0s and 1s:

# Unix:
perl -l -0777 -ne 'print unpack("B*", $_)' binary_file
# DOS (using ActiveState Perl 5.8 or later):
perl -l -Mopen=IO,:raw -0777 -ne "print unpack('B*', $_)" binary_file

(Note: Replace the 'B*' packstring with 'H*' to see the hexadecimal
equivalent.)

   Hopefully this will help you, Leonard.

   -- Jean-Luc



------------------------------

Date: Mon, 17 Jan 2005 17:19:26 GMT
From: "George" <georgekinley@hotmail.com>
Subject: MAP Question
Message-Id: <xn0dxddd97bqie8000@news.europe.nokia.com>

Hi
I needed to run regular exression(RE) for all the elements of an  array
so I thought of using MAP(one liner) insted foreach.
Following line
@Rfolder=map {/#(.*?)(?=:)/,$_} @getlistF;
gave me all the existing elements plus what is extracted by RE

but 
following line
@Rfolder=map {/#(.*?)(?=:)/} @getlistF;
gave me just what RE returned,

Definetly it means that I do not understand MAP correctly, 
can somebody please explain what is the difference between two
statement , cause what I understood that $_ needs to be set before ,
for RE to work.


------------------------------

Date: Mon, 17 Jan 2005 18:31:50 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: MAP Question
Message-Id: <jetnu092tc0mqbj3se06eigc6oi7jgjehn@4ax.com>

X-Ftn-To: George 

"George" <georgekinley@hotmail.com> wrote:
>Hi
>I needed to run regular exression(RE) for all the elements of an  array
>so I thought of using MAP(one liner) insted foreach.
>Following line
>@Rfolder=map {/#(.*?)(?=:)/,$_} @getlistF;
>gave me all the existing elements plus what is extracted by RE
>
>but 
>following line
>@Rfolder=map {/#(.*?)(?=:)/} @getlistF;
>gave me just what RE returned,
>
>Definetly it means that I do not understand MAP correctly, 
>can somebody please explain what is the difference between two
>statement , cause what I understood that $_ needs to be set before ,
>for RE to work.

You didn't say what do you want to accomplish, and I'm not sure what are
you're expectations regarding map?


-- 
Matija


------------------------------

Date: 17 Jan 2005 17:45:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: MAP Question
Message-Id: <csgtkc$t3v$2@mamenchi.zrz.TU-Berlin.DE>

George <georgekinley@hotmail.com> wrote in comp.lang.perl.misc:
> Hi
> I needed to run regular exression(RE) for all the elements of an  array
> so I thought of using MAP(one liner) insted foreach.
> Following line
> @Rfolder=map {/#(.*?)(?=:)/,$_} @getlistF;
> gave me all the existing elements plus what is extracted by RE
> 
> but 
> following line
> @Rfolder=map {/#(.*?)(?=:)/} @getlistF;
> gave me just what RE returned,
> 
> Definetly it means that I do not understand MAP correctly, 
> can somebody please explain what is the difference between two
> statement , cause what I understood that $_ needs to be set before ,
> for RE to work.

Have you read the map documentation (not "MAP", case matters)?

As it explains, the block you give to map is evaluated in list context,
with $_ set to the list elements in turn.

In the first case, the block returns whatever the regex extracts, followed
by $_.  In the second case, there is no $_ in the block, so it returns
just what the regex extracts.  What else is to explain?

Anno


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7661
***************************************


home help back first fref pref prev next nref lref last post