[26906] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8891 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 27 14:05:36 2006

Date: Fri, 27 Jan 2006 11:05:07 -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           Fri, 27 Jan 2006     Volume: 10 Number: 8891

Today's topics:
        Amount of entries in zip file [Archive::Zip (Compress:: <noaddress@ohno.email.com>
    Re: Amount of entries in zip file [Archive::Zip (Compre <1usa@llenroc.ude.invalid>
    Re: FAQ 5.8 How can I make a filehandle local to a subr <jgibson@mail.arc.nasa.gov>
        IO::Select->can_read returns immediately <glenn-nntp@this.delink.is.net.invalid>
    Re: IO::Select->can_read returns immediately xhoster@gmail.com
    Re: IO::Select->can_read returns immediately <jgibson@mail.arc.nasa.gov>
    Re: LF: Server scripting advice <tadmc@augustmail.com>
    Re: mistake in my for <zen13097@zen.co.uk>
    Re: string manipulation <1usa@llenroc.ude.invalid>
    Re: string manipulation <jurgenex@hotmail.com>
    Re: string manipulation axel@white-eagle.invalid.uk
    Re: Using arrays instaed of sequentially numbered varia <tadmc@augustmail.com>
        XSUB callback <bol@adv.magwien.gv.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 27 Jan 2006 15:59:06 GMT
From: "Twig" <noaddress@ohno.email.com>
Subject: Amount of entries in zip file [Archive::Zip (Compress::Zlib)]
Message-Id: <errCf.20135$Nb2.359147@news1.nokia.com>

Where this is defined?
I'm using perl 5.6 and writing a script to get listing of zip file 
content but getting complained of "too short file" when trying to access 
2.2 Giga zip file.
Is there available archive module which can handle bigger files than 2 
Gb's?

How to get over this?

Perl 5.6 is mandatory requirement for me, and reason to write this 
script is get rid of external utils. 



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

Date: Fri, 27 Jan 2006 16:59:42 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Amount of entries in zip file [Archive::Zip (Compress::Zlib)]
Message-Id: <Xns97587A016F925asu1cornelledu@132.236.56.8>

"Twig" <noaddress@ohno.email.com> wrote in news:errCf.20135$Nb2.359147
@news1.nokia.com:

> Where this is defined?
> I'm using perl 5.6 and writing a script to get listing of zip file 
> content but getting complained of "too short file" when trying to access 
> 2.2 Giga zip file.
> Is there available archive module which can handle bigger files than 2 
> Gb's?

I don't think it is a function of the module, but depends on how perl was 
compiled. For example:

 lseeksize 

etc.

> How to get over this?

Get a Perl that supports 64-bit file offsets.
 
> Perl 5.6 is mandatory requirement for me, and reason to write this 
> script is get rid of external utils. 

If you have a zip utility that is widely available and works with 64-bit 
offsets, why not use it?

Sinan


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

Date: Fri, 27 Jan 2006 10:19:02 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: FAQ 5.8 How can I make a filehandle local to a subroutine?  How do I pass filehandles between subroutines?  How do I make an array of filehandles?
Message-Id: <270120061019025570%jgibson@mail.arc.nasa.gov>

In article <draa96$ekj$1@reader2.panix.com>, PerlFAQ Server
<comdog@pair.com> wrote:

> This is an excerpt from the latest version perlfaq5.pod, which
> comes with the standard Perl distribution. These postings aim to 
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
> 
> --------------------------------------------------------------------
> 
> 5.8: How can I make a filehandle local to a subroutine?  How do I pass
> filehandles between subroutines?  How do I make an array of filehandles?
> 
>   
>     As of perl5.6, open() autovivifies file and directory handles as
>     references if you pass it an uninitialized scalar variable. You can then
>     pass these references just like any other scalar, and use them in the
>     place of named handles.
> 
>             open my    $fh, $file_name;
> 
>             open local $fh, $file_name;
> 
>             print $fh "Hello World!\n";
> 
>             process_file( $fh );
> 
>     Before perl5.6, you had to deal with various typeglob idioms which you
>     may see in older code.
> 
>             open FILE, "> $filename";
>             process_typeglob(   *FILE );
>             process_reference( \*FILE );
> 
>             sub process_typeglob  { local *FH = shift; print FH  "Typeglob!" }
>             sub process_reference { local $fh = shift; print $fh "Reference!"
> }
> 
>     If you want to create many anonymous handles, you should check out the
>     Symbol or IO::Handle modules.

This FAQ entry asks three questions but only attempts to answer the
first two. Shouldn't there be an example of making an array of
filehandles?

   my @fh;
   for my $i ( 0..9 ) {
      open( $fh[$i], '>', "file$i" );
      print { $fh[$i] } "File number $i\n";  # block needed
   }

or something like that, showing in particular the need to surround the
array element with a block to avoid a syntax error.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Fri, 27 Jan 2006 15:37:29 -0000
From: Brian T Glenn <glenn-nntp@this.delink.is.net.invalid>
Subject: IO::Select->can_read returns immediately
Message-Id: <slrndtkfhp.asg.glenn-nntp@ziegchen.delink.net>

I am attempting to use IO::Select to poll a FIFO created by mkfifo. The 
FIFO has absolutely no writers attached to it. The following is the 
code:

$fifo = IO::File->new();
fatal("Could not open FIFO for reading: $!") unless $fifo->open($cfg{'General'}{'FIFO'});

# Prepare to enter the main loop
$loop = IO::Select->new($fifo);
do_log(1,"Entering processing loop\n");
while(1) {
        @tasklist = $loop->can_read();
        foreach my $fh (@tasklist) {
                if ($fh == $fifo) {
                        do_log(5,"Received a message from the FIFO");
                }
                else {
                        do_log(5,"Receiving a message from another source");
                }
        }
}

__END__

Shouldn't the can_read() method block until data appears on the FIFO? I 
have tried it both with and without a timeout, and the process spins 
indefinitely, filling the syslog with "Received a message from the FIFO".

I never receive the message "Receiving a message from another source" in 
the syslog. There are also no other filehandles attached to the 
IO::Select object.

Thanks in advance,
-- 
Brian T Glenn
delink.net Internet Services


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

Date: 27 Jan 2006 17:27:04 GMT
From: xhoster@gmail.com
Subject: Re: IO::Select->can_read returns immediately
Message-Id: <20060127122729.095$Ow@newsreader.com>

Brian T Glenn <glenn-nntp@this.delink.is.net.invalid> wrote:
> I am attempting to use IO::Select to poll a FIFO created by mkfifo. The
> FIFO has absolutely no writers attached to it. The following is the
> code:

Your code is not runnable.  If I make my best guesses in order to make it
runnable, it does not display the symptoms you report.


> $fifo = IO::File->new();
> fatal("Could not open FIFO for reading: $!") unless
> $fifo->open($cfg{'General'}{'FIFO'});

What is in $cfg{'General'}{'FIFO'} ?

In my hands, the opening of a fifo with absolutely no writers attached
blocks forever.  Not the read, but the open itself.

Xho

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


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

Date: Fri, 27 Jan 2006 10:55:33 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: IO::Select->can_read returns immediately
Message-Id: <270120061055337000%jgibson@mail.arc.nasa.gov>

In article <slrndtkfhp.asg.glenn-nntp@ziegchen.delink.net>, Brian T
Glenn <glenn-nntp@this.delink.is.net.invalid> wrote:

> I am attempting to use IO::Select to poll a FIFO created by mkfifo. The 
> FIFO has absolutely no writers attached to it. The following is the 
> code:
> 
> $fifo = IO::File->new();
> fatal("Could not open FIFO for reading: $!") unless
> $fifo->open($cfg{'General'}{'FIFO'});
> 
> # Prepare to enter the main loop
> $loop = IO::Select->new($fifo);
> do_log(1,"Entering processing loop\n");
> while(1) {
>         @tasklist = $loop->can_read();
>         foreach my $fh (@tasklist) {
>                 if ($fh == $fifo) {
>                         do_log(5,"Received a message from the FIFO");
>                 }
>                 else {
>                         do_log(5,"Receiving a message from another source");
>                 }
>         }
> }
> 
> __END__
> 
> Shouldn't the can_read() method block until data appears on the FIFO? I 
> have tried it both with and without a timeout, and the process spins 
> indefinitely, filling the syslog with "Received a message from the FIFO".

Yes, since can_read is not blocking, there must be data ready to read
on the FIFO. If you don't actually read the data from the FIFO, then it
will still be ready the next time you call can_read. Try reading the
data:

   print <$fh>;

> 
> I never receive the message "Receiving a message from another source" in 
> the syslog. There are also no other filehandles attached to the 
> IO::Select object.

can_read will either return an empty list or a list with $fifo as its
only element. There is no way you can ever print "Receiving a message
from another source".

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Fri, 27 Jan 2006 07:36:43 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: LF: Server scripting advice
Message-Id: <slrndtk8fb.ltq.tadmc@magna.augustmail.com>

Dave <david@nospam.com> wrote:

> Subject: LF: Server scripting advice


What does "LF" stand for?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 27 Jan 2006 11:33:13 GMT
From: Dave Weaver <zen13097@zen.co.uk>
Subject: Re: mistake in my for
Message-Id: <43da04f9$0$23282$db0fefd9@news.zen.co.uk>

On Fri, 20 Jan 2006 21:30:03 +0100, Olaf "El BLanco" <winter@yahoo.co.uk> wrote:
> 
>  for ($a=0; $a<$max; print "\t$a", $a++) {}
>  // OK, print 1 2 3 4 5 ... max
> 
>  But
> 
>  for ($a=0; $a<$max; $a++, print "\t$a") {}
> 
>  // print 00 11 22 33 44... max-1max-1 ?
> 

Others have pointed out why you get wrong output.

If you've put the print in that position so that it will be executed
at the end every loop regardless of 'next's, you should instead use a
continue block:

for my $i (1 .. $max) {
    # ...
}
continue {
    print "\$i";
}

see "perldoc -f continue"





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

Date: Fri, 27 Jan 2006 11:10:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: string manipulation
Message-Id: <Xns97583EDB76820asu1cornelledu@127.0.0.1>

"a" <a@mail.com> wrote in news:FYiCf.454345$ki.271648@pd7tw2no:

> I have an input string. It is a full path of a file.
> eg. //server/dirA/dirB/file.txt
> How can I parse it into directory and file?
> i.e //server/dirA/dirB/ and file.txt

This is not just string manipulation. It is path and file name 
manipulation. As such, you'd better served by using File::Spec. Using the 
module would help make your script more portable.
 
> Also, I have a directory as an input.
> e.g //server/dirA/dirB/
> How can I check the last character is a / or not?

If you use File::Spec->catfile, you need not worry about that.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



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

Date: Fri, 27 Jan 2006 13:09:00 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: string manipulation
Message-Id: <MXoCf.79903$jd5.75731@trnddc02>

a wrote:
> Hi,
> I have an input string. It is a full path of a file.
> eg. //server/dirA/dirB/file.txt
> How can I parse it into directory and file?
> i.e //server/dirA/dirB/ and file.txt

As usual: use File::Basename

> Also, I have a directory as an input.
> e.g //server/dirA/dirB/
> How can I check the last character is a / or not?

As usual there are different ways:
- you could use substr() to extract the last character of the string and eq 
it with '/'
- you could use m// and anchor the RE to the end of the string
- ...

jue 




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

Date: Fri, 27 Jan 2006 15:27:05 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: string manipulation
Message-Id: <dZqCf.10218$wl.3853@text.news.blueyonder.co.uk>

a <a@mail.com> wrote:
> Also, I have a directory as an input.
> e.g //server/dirA/dirB/
> How can I check the last character is a / or not?

perldoc -f substr ... look for the bit about negative
OFFSETs in the first paragraph.

Axel
 
 


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

Date: Fri, 27 Jan 2006 08:10:00 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Using arrays instaed of sequentially numbered variables 
Message-Id: <slrndtkadn.ltq.tadmc@magna.augustmail.com>

lance-news <lance-news@augustmail.com> wrote:

> Another question based on responses I received to another post
> headed "concatenate variables during looping question".

> My basic question is how can I create arrays from the code below to
> to create a better and simpler data structure?


> These regexp'S are the same except for the middle string (i.e CLOTHEING, ITEMS ...)
> and the variable names at the end.
> 
> My initial guess would be to create an array with the regexp search string
> OVERALL RATING, CLOTHING ... 


A "list" will do, you don't need an "array".


> and another array containing the results @JA13.
> I have no idea how to set this up though?
> 
> 
> ###### JA ######
> $file=~/(TABLE\s+36.*?TABLE 37)/s;
> my $fileja=$1;


You should never use the "dollar digit" variables unless you have
first ensured that the match *succeeded*.

   die "match failed" unless $file =~ /(TABLE\s+36.*?TABLE 37)/s;
   my $fileja = $1;


> $fileja =~/TABLE\s+36.*?JA.*?OVERALL RATING.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;
> my $JA13_1 = $1;


The {1} doesn't do anything extra, so why put it in?

After you take it out, you won't need the non-capturing parenthesis either.

You probaby don't need the "prefix" part of that pattern either...


> my $JA13_1 = $1;

   $JA13[1] = $1;

or maybe:
   push @JA13, $1;


> $fileja =~/TABLE\s+36.*?JA.*?CLOTHING.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;my $JA13_2 = $1;
> $fileja =~/TABLE\s+36.*?JA.*?ITEMS.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;my $JA13_3 = $1;
> $fileja =~/TABLE\s+36.*?JA.*?ACCESSORIES.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;my $JA13_4 = $1;
> $fileja =~/TABLE\s+36.*?JA.*?SHOES.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;my $JA13_5 = $1;
> $fileja =~/TABLE\s+36.*?JA.*?FINE JEWELRY.*?MEAN.*?(?:(\d{1,3}\.\d\d)\s+){1}/s;  my $JA13_6 = $1;


   foreach my $pat ('OVERALL RATING', 'CLOTHING', 'ITEMS') {
      die "could not match '$pat'" 
         unless $fileja =~ /$pat.*?MEAN.*?(\d{1,3}\.\d\d)\s+/s;
      push @JA13, $1;
   }


> # Answers from previous post


Not quite.


> $Sheet->Cells(16, $i)->{Value} = $Ja13[$_ - 1] for 2 .. 7;
                    ^^
                    ^^

You should use copy/paste rather than retype code to avoid giving
yourself the opportunity to insert a typo like that.

Have you seen the Posting Guidelines that are posted here frequently yet?

(that was not a rhetorical question.)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 27 Jan 2006 17:30:38 +0100
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: XSUB callback
Message-Id: <1138379440.692748@proxy.dienste.wien.at>

Hi @ all perl folk here,

On a OpenVMS system with Perl 5.8.6, there are some routines in a sharable
image (well, perhaps here better known as 'libxxx.so', isn't it? ;-), I have
to made available from Perl which. I think this can be done by writing a
wrapper using the well-known XS stuff (h2xs, xsubpp & others).

However, one of these routines, when called, performs some action and then
calls back a user-supplied routine, passing this routine the address of a
structure which contains many data the routine can examine and - in some
cases - change in addition. The structure also provides the addresses of
further routines which the callback may invoke to perform additional
operations. The structure exists for the live time of the callback routine
only and its contents is processed further once the callback has terminated.

Hm. In Perl terms, I think, the callback is a perl function and the
"structure" can be expresses as a reference blessed into a package which
provides the corresponding attributes and methods. I havn't however, found,
any ways to implement a callback mechanism with XS. So my question: does
someone know here how to accomplish this. I would very appreciate some code
examples.

Many thanks for any help and kind greetings from Vienna,

Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




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

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 8891
***************************************


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