[31863] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3126 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 10 00:09:25 2010

Date: Thu, 9 Sep 2010 21:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 9 Sep 2010     Volume: 11 Number: 3126

Today's topics:
    Re: convert byte stream to integers <jwkrahn@example.com>
    Re: convert byte stream to integers <smallpond@juno.com>
    Re: convert byte stream to integers <rvtol+usenet@xs4all.nl>
    Re: convert byte stream to integers <sreservoir@gmail.com>
    Re: FAQ 5.10 How can I use a filehandle indirectly? <hjp-usenet2@hjp.at>
    Re: Ideal data structure for nested list format? <tuxedo@mailinator.com>
    Re: Ideal data structure for nested list format? <tuxedo@mailinator.com>
    Re: Ideal data structure for nested list format? <sherm.pendley@gmail.com>
    Re: Ideal data structure for nested list format? <tadmc@seesig.invalid>
    Re: Ideal data structure for nested list format? <tuxedo@mailinator.com>
    Re: Ideal data structure for nested list format? <sherm.pendley@gmail.com>
    Re: Ideal data structure for nested list format? <tadmc@seesig.invalid>
    Re: invisible objects <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 09 Sep 2010 12:31:37 -0700
From: "John W. Krahn" <jwkrahn@example.com>
Subject: Re: convert byte stream to integers
Message-Id: <uCaio.25780$EV4.20767@newsfe16.iad>

C.DeRykus wrote:
> perl -we 'open(F,"./4byte"); $,="\t"; print unpack "I*",$s while read
> F,$s,16'

You need the -l switch for that to work the same as the OP's

perl -lne'BEGIN{$/=\16;$,="\t"}print unpack"I*",$_' ./4byte



John
-- 
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein


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

Date: Thu, 09 Sep 2010 16:20:35 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: convert byte stream to integers
Message-Id: <i6bfj3$m7g$1@news.eternal-september.org>

On 09/08/2010 12:44 PM, Toralf Förster wrote:
> Steve C wrote:
>> The unpack might seem non-obvious.  It takes a string and unpacks it as a
>> perl value. The reason this step is separate from the read is that perl
>> variables have to know what type of data they contain, since they can hold
>> different types.
>
> Yep thx, I thought it could be done in one step.
>
> This is now sufficient for me :
>
> perl -we 'open (FILE, "./4byte"); while (read (FILE, my $s, 16)) { my @N =
> unpack "I*", $s; print join ("\t", @N), "\n"; } close (FILE)'
>
>


I forgot to mention that after opening a binary file, you should call
binmode on the filehandle to protect the data from unwanted text file
conversions by the I/O services.  Something like this:

  open (FILE, '<', "./4byte") or die "Unable to open file\n";
  binmode FILE;


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

Date: Fri, 10 Sep 2010 00:06:57 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: convert byte stream to integers
Message-Id: <4c895a82$0$22918$e4fe514c@news.xs4all.nl>

On 2010-09-09 22:20, Steve C wrote:

> I forgot to mention that after opening a binary file, you should call
> binmode on the filehandle to protect the data from unwanted text file
> conversions by the I/O services. Something like this:
>
> open (FILE, '<', "./4byte") or die "Unable to open file\n";
> binmode FILE;

Or just use the :raw layer, see perlio.

   open my $fh, "<:raw", $fname
       or die "Error with '$fname': ", $!;

-- 
Ruud


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

Date: Thu, 09 Sep 2010 18:18:38 -0400
From: sreservoir <sreservoir@gmail.com>
Subject: Re: convert byte stream to integers
Message-Id: <i6bmg2$not$1@news.eternal-september.org>

On 9/9/2010 3:31 PM, John W. Krahn wrote:
> C.DeRykus wrote:
>> perl -we 'open(F,"./4byte"); $,="\t"; print unpack "I*",$s while read
>> F,$s,16'
>
> You need the -l switch for that to work the same as the OP's
>
> perl -lne'BEGIN{$/=\16;$,="\t"}print unpack"I*",$_' ./4byte
>
> John

with 5.10, -E and say.

INIT does well, and unpack takes implicit $_. and a v-string for $,.

on the command line ./4byte should be the same thing as 4byte.

perl -nE'INIT{$/=\16;$,=v9}say unpack"I*"' 4byte # 9 chars shorter.

-- 

  "Six by nine. Forty two."
  "That's it. That's all there is."
  "I always thought something was fundamentally wrong with the universe."


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

Date: Thu, 9 Sep 2010 21:30:18 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.10 How can I use a filehandle indirectly?
Message-Id: <slrni8ideb.nhr.hjp-usenet2@hrunkner.hjp.at>

On 2010-09-09 10:00, PerlFAQ Server <brian@theperlreview.com> wrote:
> 5.10: How can I use a filehandle indirectly?
>
>     An indirect filehandle is using something other than a symbol in a place
>     that a filehandle is expected. Here are ways to get indirect
>     filehandles:
>
>             $fh =   SOME_FH;       # bareword is strict-subs hostile
>             $fh =  "SOME_FH";      # strict-refs hostile; same package only
>             $fh =  *SOME_FH;       # typeglob
>             $fh = \*SOME_FH;       # ref to typeglob (bless-able)
>             $fh =  *SOME_FH{IO};   # blessed IO::Handle from *SOME_FH typeglob
>
>     Or, you can use the "new" method from one of the IO::* modules to create
>     an anonymous filehandle, store that in a scalar variable, and use it as
>     though it were a normal filehandle.
>
>             use IO::Handle;                     # 5.004 or higher
>             my $fh = IO::Handle->new();

I think this should also mention lexical filehandles.

[...]

>     With "print" and "printf", you get around this by using a block and an
>     expression where you would place the filehandle:
>
>             print  { $fd[1] } "funny stuff\n";
>             printf { $fd[1] } "Pity the poor %x.\n", 3_735_928_559;
>             # Pity the poor deadbeef.
>
>     That block is a proper block like any other, so you can put more
>     complicated code there. This sends the message out to one of two places:
[...]
>     This approach of treating "print" and "printf" like object methods calls

If you use IO::Handle, you can also use the arrow notation, which I find
more readable for complicated expressions:

            $fd[1]->print("funny stuff\n");
            $fd[1]->printf("Pity the poor %x.\n", 3_735_928_559);

	hp



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

Date: Thu, 9 Sep 2010 17:40:43 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Ideal data structure for nested list format?
Message-Id: <i6av5s$1sk$02$1@news.t-online.com>

sln@netherlands.com wrote:

[...]

Thanks for posting your code! However, when running it I get the following 
output:

Sequence (?1...) not recognized in regex; marked by <-- HERE in m/
  ( #1
    \( 
      ( #2
        (?:
          (?> [^()]+ )
          | (?1 <-- HERE )
        )*
      ) 
    \)
  )
|
  ( #3
    \[ 
      ( #4
        (?:
          (?> [^\[\]]+ )
          | (?3)
        )*
      ) 
    \]
  )
|
 '\s* ([^']*)\s*'\s*, ([^<\n]*)  #5,6
/ at ./tmp/temp.pl line 45.

I'm sure your script produced the other output you posted on your own 
system. Maybe I have another regex engine in my perl or something. My 
system reports my Perl version as 5.008008, which is obviously not the 
latest version.

Tuxedo


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

Date: Thu, 9 Sep 2010 18:23:25 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Ideal data structure for nested list format?
Message-Id: <i6b1lt$70v$02$1@news.t-online.com>

Ben Morrow wrote:

Thanks for checking and taking the time commenting line-by-line!

> If this isn't your actual code (you *have* read the Posting Guidelines,
> right?) and the title is not necessarily the name of the page, you just
> need a regex capture:

I didn't read the gudelines. I guess they state something like example code 
should reflect real code as close as possible. So you are right in guessing 
that the page name will not be repeated in the title.

>     $complete_string =~ s[<a href="$this_page">(.*?)</a>][$1]s;
> 
> The '?' there is important: it stops the pattern matching everything up
> to the final '</a>' in the file.

Thanks for this too and all the other pointers, which helps me learn 
something new as well as making the script slightly more manageable, at 
least until a better version exists, i.e. one that uses a nested data 
structure rather than my flat printing combined with a series of repetitive 
regex rewrite calls to simply reformat the output. Yet, it works :-)

Tuxedo


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

Date: Thu, 09 Sep 2010 12:29:39 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Ideal data structure for nested list format?
Message-Id: <m2y6bag9sc.fsf@sherm.shermpendley.com>

Tuxedo <tuxedo@mailinator.com> writes:

> I didn't read the gudelines. I guess they state something like
> example code should reflect real code as close as possible.

No, that's not what the guidelines say. Please read them, so you won't
have to guess next time.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Thu, 09 Sep 2010 11:56:32 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Ideal data structure for nested list format?
Message-Id: <slrni8i3uu.b6r.tadmc@tadbox.sbcglobal.net>

Tuxedo <tuxedo@mailinator.com> wrote:
> Ben Morrow wrote:
>
> Thanks for checking and taking the time commenting line-by-line!
>
>> If this isn't your actual code (you *have* read the Posting Guidelines,
>> right?) and the title is not necessarily the name of the page, you just
>> need a regex capture:
>
> I didn't read the gudelines.

    This article describes things that you should, and should not, 
    do to increase your chances of getting an answer to your Perl question.


If you would like to increase your chances of getting an answer,
then you should read them...


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 9 Sep 2010 19:17:32 +0200
From: Tuxedo <tuxedo@mailinator.com>
Subject: Re: Ideal data structure for nested list format?
Message-Id: <i6b4rc$d73$02$1@news.t-online.com>

Sherm Pendley wrote:

> No, that's not what the guidelines say. Please read them, so you won't
> have to guess next time.

I'll surely get around to that one day...

Tuxedo



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

Date: Thu, 09 Sep 2010 18:08:23 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Ideal data structure for nested list format?
Message-Id: <m2aanq1sfc.fsf@sherm.shermpendley.com>

Tuxedo <tuxedo@mailinator.com> writes:

> Sherm Pendley wrote:
>
>> No, that's not what the guidelines say. Please read them, so you won't
>> have to guess next time.
>
> I'll surely get around to that one day...

One day soon, please. Doing so will be *far* more useful to you than
the snotty attitude you seem to think is appropriate here.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Thu, 09 Sep 2010 21:59:55 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Ideal data structure for nested list format?
Message-Id: <slrni8j7ov.d3t.tadmc@tadbox.sbcglobal.net>

Tuxedo <tuxedo@mailinator.com> wrote:
> Sherm Pendley wrote:
>
>> No, that's not what the guidelines say. Please read them, so you won't
>> have to guess next time.
>
> I'll surely get around to that one day...


Too late.

Off to perpetual invisibility with you!


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Thu, 09 Sep 2010 10:25:40 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: invisible objects
Message-Id: <87lj7b547f.fsf@lifelogs.com>

On Wed, 08 Sep 2010 13:37:03 -0700 merlyn@stonehenge.com (Randal L. Schwartz) wrote: 

>>>>>> "monkeys" == monkeys paw <monkey@joemoney.net> writes:
monkeys> I need the items in @array to have callable methods.

RLS> Then they need to be objects.

They could be tied hashes and the passed key could be a JSON dump of the
parameters ;)

Ted


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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3126
***************************************


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