[23970] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6171 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 21 03:05:41 2004

Date: Sat, 21 Feb 2004 00:05:09 -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           Sat, 21 Feb 2004     Volume: 10 Number: 6171

Today's topics:
        building an array of hashes from MP3::Info (shambolic)
    Re: Email::Valid bug? <matthew.garrish@sympatico.ca>
    Re: help on hash of hashes (Stephen Moon)
    Re: how to cut a text file in perl <toylet@mail.hongkong.com>
    Re: How to Tie Existing File to Hash <gkincade1@austin.rr.com>
    Re: I wish buy Perl book <matthew.garrish@sympatico.ca>
    Re: I wish buy Perl book (Randal L. Schwartz)
    Re: I wish buy Perl book <toylet@mail.hongkong.com>
    Re: I wish buy Perl book <toylet@mail.hongkong.com>
    Re: Installation Problem with XML::Parser perl module <usenet@morrow.me.uk>
        Let browser say "done" immediately after parent finish  (Zhidian Du)
    Re: Listbox and passing entries <sales@microsoft.com>
    Re: Listbox and passing entries <Joe.Smith@inwap.com>
    Re: more stripping <Joe.Smith@inwap.com>
    Re: Multiple substitution in a complex RE <fifo@despammed.com>
        Net::FTP listing of directory (mike)
    Re: Net::FTP listing of directory <tony_curtis32@_SPAMTRAP_yahoo.com>
    Re: Newbe Unicode question <usenet@morrow.me.uk>
    Re: Newbie question on use (Malcolm Dew-Jones)
        passing parameters to Net::FTP (mike)
        perl fileio <toylet@mail.hongkong.com>
    Re: perl fileio <tassilo.parseval@rwth-aachen.de>
    Re: Posting Usenet News Messages <Joe.Smith@inwap.com>
    Re: trapping file i/o error <Joe.Smith@inwap.com>
    Re: trapping file i/o error <toylet@mail.hongkong.com>
    Re: Unexplained output for PERL print statement <Joe.Smith@inwap.com>
    Re: Why is Perl losing ground? (Unknown Poster)
    Re: XML to Class::Struct <shirsch@adelphia.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Feb 2004 17:40:17 -0800
From: j@shambolic.com (shambolic)
Subject: building an array of hashes from MP3::Info
Message-Id: <35ecb3b5.0402201740.141ecede@posting.google.com>

Hi,

a few newby questions on building more complex data structures, if
that's ok.

i want to find duplicate mp3 files on my hardrive based on near
matches for track title (TITLE) and Filename using MP3::Info.

i have array @mp3s, of all the mp3 files on my drive, and looping
through that get a hash of mp3 tags for each file (%hash). i then push
%hash into an array, which i can loop through to compare duplicates,
etc.


so something along the lines of:

use warnings;
use strict;
use MP3::Info;

# == snip: build @mp3s using File::Find ==

for my $file(@mp3s) {
next unless /mp3/;

#    create hash with tag metadata
print "trying to get tag for:$file\n\n";
my $tag = get_mp3tag("$file") or die "no TAG info: $!";
my %hash= %$tag;

#    create array of hashes
push my @files, {%hash};

#    loop through array of hashes

for my $i (0 ..$#files) {
   for my $element (keys %{ $files[$i] } ) {
   	
   	#  insert find duplicate code here.  
   	
   	print "$element is $files[$i]{$element}\n";
   }
}

so my questions are:
* are there any modules that would do this better?
* is it better to use an array of hashes or a hash of hashes (i've
found it easier to use the array)?
* what is the best way to match approximate values for filenames and
TITLES? maybe String::Approx?
* any other tricks i've (probably) missed with respect to design or
approach?

many thanks in advance

j


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

Date: Fri, 20 Feb 2004 18:28:42 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Email::Valid bug?
Message-Id: <IKwZb.11822$Cd6.850668@news20.bellglobal.com>


"Guru03" <Guru03@despammed.com> wrote in message
news:Xns9495A474ADCE3Guru03despammedcom@193.43.96.1...
> Glenn Jackman <xx087@freenet.carleton.ca> wrote in
> news:slrnc3c6fr.dm5.xx087@smeagol.ncf.ca:
>
> > Guru03 <Guru03@despammed.com> wrote:
> >>  print Email::Valid->rfc822 ('<ppp@ppp.com>');
> >>  it says error. Why?
> >
> > Because, according to RFC 822, it is not valid.
> >     http://www.faqs.org/rfcs/rfc822.html
> >
> > If you use <angle brackets>, you have to precede it with a phrase, which
> > is one or more words.  This is valid:
> >     Email::Valid->rfc822 ('my name <ppp@ppp.com>');
>
> Mmmh...
>
> it's RFC 2822 Valid. See in appendix A.1.2 of RFC 2822...
>

And RFC2822 is still only a proposed standard, so what is your point?

Matt




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

Date: 20 Feb 2004 18:56:45 -0800
From: vibfft@yahoo.com (Stephen Moon)
Subject: Re: help on hash of hashes
Message-Id: <9feadd98.0402201856.5b18b339@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c15lb1$l05$1@mamenchi.zrz.TU-Berlin.DE>...
> Stephen Moon <vibfft@yahoo.com> wrote in comp.lang.perl.misc:
> > Hi,
> > 
> > Can you help me with the below error?  Thanks in advance.
> 
> [lots of code snipped]
> 
> Do not dump your problem as is to the newsgroup, make an attempt to
> solve it yourself first.
> 
> The code I snipped contained things like checking the number of parameters
> in @ARGV.  Why should hundreds of people have to read that code,
> understand what it does, and ignore it?  It's your job to do that.
> 
> > foreach my $family ( keys %HoH ) {
> >     print "$family: ";
> >     foreach my $role ( keys %{ $HoH{$family} } ) {
> >          printf(DATA_OUT "$role=$HoH{$family}{$role}"); <= error here
> 
> Don't say "printf" when you mean "print".  There's a difference, and
> some day it will bite you.  Also, I suppose you want to print a line
> feed inside the loop too.
> 
> >     }
> >     printf(DATA_OUT "\n");
> > }
> > 
> > output error:
> > ====================================================
> > 
> > Use of uninitialized value in concatenation (.) or string at test.pl
> > line 34, <DATA_IN> line 3.
> 
> That's not an error but a warning, so the program should have printed
> something to the output file.  It would be interesting to know what
> it was, but you didn't supply it.
> 
> In any case, you have not exhausted your own means by a long shot.
> 
> The warning tells you there's an undefined value in a string, so
> at least one of "$role" or "$hoh{$family}{$role}" is undefined.
> 
> To find out which, change the code to tell you:
> 
> foreach my $family ( keys %HoH ) {
>     print "$family: ";
>     foreach my $role ( keys %{ $HoH{$family} } ) {
>          die '$role' unless defined $role;
>          die '$HoH{$family}{$role}' unless defined $HoH{$family}{$role};
>          print "$role=$HoH{$family}{$role}";
>     }
>  print "\n";
> }
> 
> I bet you'll find that "$role" is defined but "$HoH{$family}{$role}" isn't.
> 
> Ask yourself why you think it should have a value.  Then go back through 
> your code and verify that it does what you think it does.
> 
> In other words, learn to debug a program.  It's a skill as necessary as
> writing it in the first place.
> 
> Anno

Thanks for all your help.

Well, the above code is not mine.  It's actually taken out from the
Programming Perl Third Edition book (i.e. Camel book).  I was trying
to figure out how to generate a hash of hashes and how to print them
out by trying out his examples, but somehow I couldn't not get it to
work.

-Steve


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

Date: Sat, 21 Feb 2004 15:18:32 +0800
From: toylet <toylet@mail.hongkong.com>
Subject: Re: how to cut a text file in perl
Message-Id: <4037063f$1_3@rain.i-cable.com>

actually, this is to _truncate_ a log.

Joseph wrote:

> hi i have a log file that it is increasing to big, how can i keep this
> file of
> a certain size, in other words, how can i make sure that the file is
> only 200 lines long and delete the first lines if longer. i think it
> would be easier to write this in a shell script. but i have no idea 
> in perl. can anyone tell me how to print the last 200 lines of a file
> and overwrite the ssame file. thanks.

-- 
   .~.    Might, Courage, Vision. In Linux We Trust.
  / v \   http://www.linux-sxs.org
/( _ )\  Linux 2.4.22-xfs
   ^ ^    3:18pm up 15:38 1 user 1.00 1.00


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

Date: Fri, 20 Feb 2004 21:37:29 GMT
From: "SpecialK" <gkincade1@austin.rr.com>
Subject: Re: How to Tie Existing File to Hash
Message-Id: <t6vZb.11247$jl.469@fe2.texas.rr.com>

I have a 150k line file that I am trying to convert to a hash.
Each line has a number, e.g. first line has 50000000, last line has 50149999
The message I get is basically, I am running of shared memory.
Here is the code:


use IPC::Shareable;
%ShmOptions = ('create' =>1, 'exclusive'  =>0, 'mode' =>0666, 'destroy'
=>0);
eval {tie(%hashofGuids, 'IPC::Shareable', 'hashguid', %ShmOptions}) };
my guidfile ='/home/gregk/www/guid_excluded.dat';

open(GUIDS, guidfile) or die "couldn't open file: $!";
(tied %hashofGuids)->shlock;
while(<GUIDS>)
 {
   chomp($eachline = $_;
   $hashofGuids{$eachline} = 1;
  }
(tied %hashofGuids)->shunlock;
## At this point I get the running out of shared memory message  ###

I tried used size=>xxx in the %ShmOptions statement but I get an invalid
size error message.

I am open to any suggestions,

thanx,
greg



"WC -Sx- Jones" <supercalifragilisticexpialidocious@insecurity.org> wrote in
message news:4034FF31.5020405@insecurity.org...
> SpecialK wrote:
> > Does anyone know how to tie a large existing file(each record is a 8byte
> > number) to a Hash using IPC::Shareable?
> > Any Code fragments would be most helpful.
>
> Why doesnt:
>
> http://search.cpan.org/~bsugars/IPC-Shareable-0.60/lib/IPC/Shareable.pm
>
> Address your question?
> -Sx-
>
> PS - See also:
> http://london.pm.org/pipermail/london.pm/Week-of-Mon-20030818/020948.html


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

Date: Fri, 20 Feb 2004 18:37:03 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: I wish buy Perl book
Message-Id: <ySwZb.11823$Cd6.851274@news20.bellglobal.com>


"Uri Guttman" <uri@stemsystems.com> wrote in message
news:x7wu6hiqe0.fsf@mail.sysarch.com...
> >>>>> "t" == toylet  <toylet@mail.hongkong.com> writes:
>
>   t> read them online. :)
>   t> http://iis1.cps.unizar.es/Oreilly/perl/
>
> you are supporting and promoting thieves.
>

Sadly, the thief in question not only left in the copyright marks, but also
reproduced O'Reilly's copyright on his site. Not an auspicious beginning to
his life of crime...

Matt




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

Date: Sat, 21 Feb 2004 02:21:41 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: I wish buy Perl book
Message-Id: <93ccbce26a500a82bd7d4eeed6f9cba4@news.teranews.com>

>>>>> "Matt" == Matt Garrish <matthew.garrish@sympatico.ca> writes:

Matt> Sadly, the thief in question not only left in the copyright
Matt> marks, but also reproduced O'Reilly's copyright on his site. Not
Matt> an auspicious beginning to his life of crime...

That's a trivial loading of the Perl CD Bookshelf onto a web server.
I've seen it before, reported it before.  O'Reilly is happy to make
the appropriate threatening sounds, and that usually gets it cleared
up in a few days or so.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Sat, 21 Feb 2004 14:48:31 +0800
From: toylet <toylet@mail.hongkong.com>
Subject: Re: I wish buy Perl book
Message-Id: <4036ff36$1_2@rain.i-cable.com>

It's actually found by google.com. I myself has my own stock of web 
server cd shelf. I was not promoting the site. Maybe I should just post 
http://www.google.com

> I wouldn't - this is probably an *illegal* copy of the CD Bookshelf.
> 
> I'm thinking O'Reilly will thank you for posting this web address on the
> 'Net.  Too bad the best you'll get out of this is good karma :-)
> 

-- 
   .~.    Might, Courage, Vision. In Linux We Trust.
  / v \   http://www.linux-sxs.org
/( _ )\  Linux 2.4.22-xfs
   ^ ^    2:46pm up 15:06 1 user 1.00 0.99


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

Date: Sat, 21 Feb 2004 14:49:50 +0800
From: toylet <toylet@mail.hongkong.com>
Subject: Re: I wish buy Perl book
Message-Id: <4036ff85$1_2@rain.i-cable.com>

This kind of links could easily be found by google. There are even *.edu 
that did that, Notably in certain 3rd world countries. I had nothing to 
do with the site. DOn't mis-understand.

> That's a trivial loading of the Perl CD Bookshelf onto a web server.
> I've seen it before, reported it before.  O'Reilly is happy to make
> the appropriate threatening sounds, and that usually gets it cleared
> up in a few days or so.

-- 
   .~.    Might, Courage, Vision. In Linux We Trust.
  / v \   http://www.linux-sxs.org
/( _ )\  Linux 2.4.22-xfs
   ^ ^    2:48pm up 15:08 1 user 1.00 0.99


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

Date: Sat, 21 Feb 2004 01:29:29 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Installation Problem with XML::Parser perl module
Message-Id: <c16c9p$ckt$2@wisteria.csv.warwick.ac.uk>


harish_ng@yahoo.com (HarishN) wrote:
> I just installed the XML::Parser and when I tried to run a test I see
> this following error.
> Parser.pm and Expat.pm versions don't match at
> /my/local/harishn/perl-modules/lib/5.6.1/sun4-solaris/XML/Parser.pm
> line 16.
>  
> I looked at the source code in these 2 modules.
>  
> package XML::Parser;
>  
>   $VERSION = '2.34';
>
> package XML::Parser::Expat;
>  
> $VERSION = "2.34" ;
>  
> I see both versions match but I still get the error. Can you anyone
> help in resolving this ?

Is there another XML/Parser/Expat.pm somewhere in @INC that is getting loaded
first?

Try adding

BEGIN {
    $SIG{__DIE__} = sub {
        die <<DIE
Parser.pm is $INC{'XML/Parser.pm'}
Expat.pm  is $INC{'XML/Parser/Expat.pm'}
$@
DIE
    }
}

at the top of your program.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: 20 Feb 2004 20:58:29 -0800
From: zdu@cs.nmsu.edu (Zhidian Du)
Subject: Let browser say "done" immediately after parent finish and do not wait child.
Message-Id: <e4c69a32.0402202058.35a603cc@posting.google.com>

I am writing a CGI program.  

Why browsers always wait (saying "transferring data from..." from the
status bar) until both parent and chilld finish and say "done".

How can I let browser say "done" immediately after parent finish.


I use a query->end_html() in there and it doesn't work.

Thanks.


FORK: {  

  if ( $pid = fork ) {

    print "Wait for a couple minutes and get your result via email\n";

    print $query->end_html();
    
    exit 0;
  }
  elsif ( defined $pid ) {

    #running a couple minutes here

  }
  elsif ( $! == EAGAIN )  {
    sleep 3;
    redo FORK;
  }
  else {
 
    print " Could not fork $!";
    return 0;
  }


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

Date: Sat, 21 Feb 2004 15:30:45 +1030
From: Henry <sales@microsoft.com>
Subject: Re: Listbox and passing entries
Message-Id: <sales-F2DAD6.15304421022004@duster.adelaide.on.net>

In article <ZtOYb.19369$M76.3455@fe2.texas.rr.com>,
 "Old School" <a@b.com> wrote:

> example:
> <select multiple size="3" name=LCHAR> (no value specified)
> <option>1</option>(selected)
> <option>2</option>
> <option>3</option>(selected)

Maybe ther problem is with the browser?  What happens when you use this 
sort of HTML?

<SELECT multiple size="3" name="LCHARS">
<OPTION value="1">1</OPTION>
<OPTION value="2">2</OPTION>
<OPTION value="3">3</OPTION>
</SELECT>

And have you checked the contents of $form{LCHAR} to make sure there are 
actually multiple values in there to split?

Henry.


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

Date: Sat, 21 Feb 2004 07:41:28 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Listbox and passing entries
Message-Id: <IYDZb.234179$U%5.1491729@attbi_s03>

Old School wrote:

> I'm at the mercy of my hosting company, and cgi-lib.pl should be able to do
> the same as CGI.pm in this regard with lower overhead.  But it is just
> returning the last item in the multiple selections.

I see you've run across yet another one of the known bugs in cgi-lib.pl.

The only practical answer is to use something other than the cgi-lib.pl
that comes from the hosting company.

Since you can upload perl scripts to the server, you can obviously
upload perl library files to the server.  Such as storing a copy
of CGI.pm in your personal directory.  Why not do that?
	-Joe


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

Date: Sat, 21 Feb 2004 07:12:17 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: more stripping
Message-Id: <lxDZb.93848$uV3.558597@attbi_s51>

Michael Hill wrote:

>>for example, I have seen roll-your-owners use unsafe methods to
>>import querystring/form params into program symboltable.
>>like cgi?foo=1&bar=x being evaled into $foo and $bar.
> 
> And how does the cgi.pm module help there? 
> If those params are unsafe the developer should be using 'post' instead
> of a 'querystring'.

You missed the whole point of gnari's post.

Some hand-rolled code does something as stupid as
   /(\w+)=([^&])/ && eval '$'.$1."=$2";
to set '$foo=1' and '$bar=x';

CGI.pm does the right thing by putting the parameters into
a hash.  The unsafeness of the parameter names are not affected
in any why by using POST.
	-Joe


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

Date: Sat, 21 Feb 2004 00:40:44 +0000
From: fifo <fifo@despammed.com>
Subject: Re: Multiple substitution in a complex RE
Message-Id: <20040221004041.GA8880@fleece>

At 2004-02-20 12:05 -0800, SqlSlinger wrote:
> fifo <fifo@despammed.com> wrote in message news:<20040219143341.GA14410@fleece>...
> > If you need a single substitution to work over the entire file, how
> > about doing something like
> > 
> >   s/                   ([a-zA-Z0-9])([a-zA-Z0-9]*)(?=_[a-zA-Z0-9_])
> >    | (?<=[a-zA-Z0-9_]_)([a-zA-Z0-9])([a-zA-Z0-9]*)
> >  /\U$1$3\L$2$4/xg
> 
> Prints A_Really_Long_Variable_Name.  Can we lose the underscores?

Sure, you just need to transpose two characters:

  s/                   ([a-zA-Z0-9])([a-zA-Z0-9]*)(?=_[a-zA-Z0-9_])
   | (?<=[a-zA-Z0-9_])_([a-zA-Z0-9])([a-zA-Z0-9]*)
   /\U$1$3\L$2$4/xg

Now you should get AReallyLongVariableName.


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

Date: 20 Feb 2004 20:11:17 -0800
From: s99999999s2003@yahoo.com (mike)
Subject: Net::FTP listing of directory
Message-Id: <dfd17ef4.0402202011.73334740@posting.google.com>

hi

can the standard Net::FTP list out the files in a directory with
timestamp?
tHat is there is a listing of the files as well as the timestamp of
the files, much like that of "ls -ltr" ??
thanks


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

Date: Fri, 20 Feb 2004 22:18:15 -0600
From: Tony Curtis <tony_curtis32@_SPAMTRAP_yahoo.com>
Subject: Re: Net::FTP listing of directory
Message-Id: <87ad3dqd4o.fsf@limey.hpcc.uh.edu>

>> On 20 Feb 2004 20:11:17 -0800,
>> s99999999s2003@yahoo.com (mike) said:

> hi can the standard Net::FTP list out the files in a
> directory with timestamp?  tHat is there is a listing of the
> files as well as the timestamp of the files, much like that
> of "ls -ltr" ??

It all depends on what the remote ftp server is prepared to
do.

But Net::FTP::dir() is probably your best bet.



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

Date: Sat, 21 Feb 2004 01:24:55 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Newbe Unicode question
Message-Id: <c16c17$ckt$1@wisteria.csv.warwick.ac.uk>


Scott_Starker@sil.org (Scottie) wrote:
> 
> Well, the zapotecUnicode.txt is a file the contains a "dictionary" of
> Zapotec word (spoken in Mexico) and it's Spanish words as it's
> definitions. It's almost a database type-of-thing. The program is
> called Shoebox. There are different lines for each record. They all
> start with "\lx" (lexicon). Then the definition(s) (\gn) follows.
> There might at least one subentry (\se) along with it's definition(s)
> (\sgn). There's more than these fields. (The Perl line "print "**";
> was for testing purposes.) Thus, I therefor I need a @Fld = split(" ",
> $_, 9999); that takes an array like this. Can you help me out? I need
> to know how to get the line into @Fld.

Well, that's easy:

    my @F = split ' ';

if the records on each line are space-separated. Alternatively,

    my @F = split /\\/;

may work better, as it will split the line on the backslashes. There are
two 'unfortunately's here: firstly, you'll get an initial empty field,
before the first backslash; secondly, the actual backslashes themselves
will be removed, so you'll have to remember to put them back in.

It's probably easiest if you then iterate over the fields, and do
whatever you need to based on the field type:

#!/usr/bin/perl -lanF\\
# see perldoc perlrun for the above: it automagically iterates over all
# lines and splits them into @F

BEGIN {
    $\ = '';
    binmode STDIN,  ':encoding(utf8)';
    binmode STDOUT, ':encoding(utf8)';
}

for (@F) {
    /^lx/ and next;

    /^gn/ and do {
        s/\xB8/|b/;   # or whatever it is you want to do
        next;
    };
}
continue {
    # this makes sure each entry gets printed, with its backslash,
    # when you're done with it.
    
    print '\\' . (join $,, @_) . $\;
}

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: 20 Feb 2004 15:18:59 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Newbie question on use
Message-Id: <403695e3@news.victoria.tc.ca>

Jimi-Carlo Bukowski-Wills (jimicarlo@ntlworld.com) wrote:
: Since @INC is global, you should see /path in @INC in any script using 
: module A directly or indirectly. 

assuming you haven't local'ized @INC.


--
Web Work Wanted, Perl Projects Programmed, Database Development Done.

I'm looking for telecommute projects. (Paying that is, various
arrangements possible.)


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

Date: 20 Feb 2004 20:42:31 -0800
From: s99999999s2003@yahoo.com (mike)
Subject: passing parameters to Net::FTP
Message-Id: <dfd17ef4.0402202042.4bbb800@posting.google.com>

hi
i create a subroutine


sub ftpget {
        $filetype = $_[0]
	my $ftp = Net::FTP->new("$FTPSERVER");
	$ftp->login("$FTPUSER" , "$FTPPASS");
	$ftp->cwd("/path");
	@listing = $ftp->dir("$filetype") ;
	$ftp->quit;
	return @listing;
} #end sub


my @list = ftpget("text*") ;
print @list;


I want to get a listing of all files begining with "text" but the
results show otherwise. What is wrong?
thanks


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

Date: Sat, 21 Feb 2004 14:57:02 +0800
From: toylet <toylet@mail.hongkong.com>
Subject: perl fileio
Message-Id: <40370135$1_3@rain.i-cable.com>

use strict;

my $buffer;
open INFILE, "/etc/textfile";
while <INFILE> {
   $buffer=$_;
}
close INFILE;

Is $buffer a null-terminated string? Does it contain the end-of-line or 
end-of-file character? Is it the reason to use chop() and chomp() on 
$buffer?

Most perl examples use text files. What if one wants to read a binary 
file? How to specify the number of bytes to read when there is no known 
position of end-of-line character? read it all into memory by 
$buffer=<INFILE> and let virtual memory cater for it?


-- 
   .~.    Might, Courage, Vision. In Linux We Trust.
  / v \   http://www.linux-sxs.org
/( _ )\  Linux 2.4.22-xfs
   ^ ^    2:52pm up 15:12 1 user 1.01 0.99


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

Date: 21 Feb 2004 08:03:59 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: perl fileio
Message-Id: <c173df$neo$1@nets3.rz.RWTH-Aachen.DE>

Also sprach toylet:

> use strict;
> 
> my $buffer;
> open INFILE, "/etc/textfile";
> while <INFILE> {
>    $buffer=$_;
> }
> close INFILE;
> 
> Is $buffer a null-terminated string? Does it contain the end-of-line or 
> end-of-file character? Is it the reason to use chop() and chomp() on 
> $buffer?

$buffer is null-terminated inside of perl, yes. But this is hardly ever
your concern. Null-terminated strings are an issue when you are
programming C or so, but not Perl. Observe:

    perl -MDevel::Peel -e 'Dump("foobar")'
    SV = PV(0x814b9ac) at 0x81430a0
      REFCNT = 1
      FLAGS = (POK,READONLY,pPOK)
      PV = 0x8158e40 "foobar"\0
      CUR = 6
      LEN = 7

The PV slot is a pointer to the underlying C string which needs to have
a terminating null character. CUR is the equivalent of Perl's length()
and LEN is the physical amount of bytes (it is here CUR+1 because of the
null-termination).

When reading through a file linewise, the string will contain the
newline characters. chomp() removes it for you. Or more correctly: it
chops off the value of the special variable $/ when it finds it at the
end of the string.

chop() on the other hand always removes the last character no matter
what it is. chomp() is therefore what you should be using.

> Most perl examples use text files. What if one wants to read a binary 
> file? How to specify the number of bytes to read when there is no known 
> position of end-of-line character? read it all into memory by 
> $buffer=<INFILE> and let virtual memory cater for it?

There are several ways. You could use read():

    my $bytes_read = read INFILE, my $buffer, 4096;

But you can also use the readline() operator. In this case, set $/ to a
reference to a number:

    local $/ = \4096;
    while (<INFILE>) {
	...
    }

That will make perl read the file in chunks of 4096 bytes.

When dealing with binary files, it can never hurt to binmode() the
filehandle before doing any reads or writes on it:

    binmode INFILE;

On Windows, this is obligatory or otherwise the IO subsystem will
translate Windows newlines ("\015\012") to the logical newline \n.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 21 Feb 2004 07:34:33 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Posting Usenet News Messages
Message-Id: <cSDZb.358466$I06.3776419@attbi_s01>

Ben Morrow wrote:

>>I've heard (on clpm) that you you shouldn't use \n after $! as it
>>supresses messages (or something like that). YMMV
> 
> It's nothing to do with $!, rather to do with warn and die. If you put
> "\n" on the end, it will suppress the line-number and file information,
> which is usually essential to debugging any problem.

Line numbers and source-file info is very programmer-friendly.

For errors that are expected to occur (such as when a user
misspells the name of an input file or specifies an output
file that is write protected), it's better write a user-friendly
error message, and include the trailing "\n" to surpress
unneeded/confusing clutter.
	-Joe


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

Date: Sat, 21 Feb 2004 06:57:37 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: trapping file i/o error
Message-Id: <BjDZb.29460$4o.45364@attbi_s52>

toylet wrote:

>> Be sure to include $! in the error message; it has strerror(errno).
> 
> 
> "$!" is a text message. can I get the errorno?
> is it "$?" as in bash?

$! = 28;	# ENOSPC = 'No space left on device'
print "As a string, the last error was '$!'\n";
print "As a number, errno was ", $!+0, "\n";

That is, $! is magic.  See also 'perldoc perlvar'.
	-Joe


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

Date: Sat, 21 Feb 2004 15:31:06 +0800
From: toylet <toylet@mail.hongkong.com>
Subject: Re: trapping file i/o error
Message-Id: <40370930$1_3@rain.i-cable.com>

Thank you. Seems that perl requires the programms the know about context.

> print "As a string, the last error was '$!'\n";
> print "As a number, errno was ", $!+0, "\n";

-- 
   .~.    Might, Courage, Vision. In Linux We Trust.
  / v \   http://www.linux-sxs.org
/( _ )\  Linux 2.4.22-xfs
   ^ ^    3:28pm up 15:48 1 user 1.02 1.00


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

Date: Sat, 21 Feb 2004 07:52:21 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Unexplained output for PERL print statement
Message-Id: <V6EZb.366812$xy6.1921288@attbi_s02>

Scott Bryce wrote:

> Because a DOS file uses a CR/LF pair to as a newline character. Chop 
> removed the Line Feed and left the Carriage Return in place. Chomp would 
> have removed both the Carriage Return and the Line Feed.

When reading a DOS file on Windows, chomp removes both characters.

When reading a DOS file on Linux (Samba shares or FTP binary or socket),
chomp() won't remove the CR part of CRLF unless the $/ variable has
been explicitly set.
	-Joe


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

Date: 20 Feb 2004 18:23:47 -0800
From: use63net@yahoo.com (Unknown Poster)
Subject: Re: Why is Perl losing ground?
Message-Id: <c62e93ec.0402201823.69ec50f4@posting.google.com>

Beable van Polasm <beable+unsenet@beable.com.invalid> wrote in message news:<ee8yj1ur2v.fsf@dingo.beable.com>...

> 
> Have you tried using one of these modules: Class::Struct,
> Class::MethodMaker, or Class::MakeMethods?

This is a good example of why Perl is losing ground as object-oriented methods
become more popular.  There are simply too many approaches to object-oriented
programming.  In addition to these, and other similar modules that are
sure to come, there's autloading, closures, "use fields", etc.  So, before
you can even start, if you want to be thorough, you have to investigate
all these approaches and decide on some criteria that a choice will be
made on.  

Then, there's the problem of integrating your OO code with that produced
by another team /department / company.  The methodology will more than likely
be so different as to make this task a real bear.


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

Date: Fri, 20 Feb 2004 22:13:38 -0500
From: "Steven N. Hirsch" <shirsch@adelphia.net>
Subject: Re: XML to Class::Struct
Message-Id: <lpmdnXUQcvRCUavdRVn-ug@adelphia.com>

Andrew V. Tkachenko wrote:
> Hello.
> 
> Does anybody know about existing module wich can do such a trick ?
> I mean, converting XML tree into pre-defined Class::Struct ?

You can convince SOAP::Lite to do this for you by means of a custom 
deserializer.  It may take some playing around and reading of source code.


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

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


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