[22476] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4697 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 12 00:06:05 2003

Date: Tue, 11 Mar 2003 21:05:08 -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           Tue, 11 Mar 2003     Volume: 10 Number: 4697

Today's topics:
    Re: dbm lock problem <goldbb2@earthlink.net>
    Re: dbm lock problem <peakpeek@purethought.com>
    Re: Forcing format to print top of page <wksmith@optonline.net>
    Re: Letting users change their password via web form... <Mandrake@dream-server.com>
        LWP with cookie and Form not working (R Solberg)
    Re: Merging log files using hash - good idea/possible? (Alan Barclay)
    Re: my $x = 100 for 1..3  why is $x undef <mgjv@tradingpost.com.au>
    Re: my $x = 100 for 1..3  why is $x undef <jihghong@yahoo.com.tw>
    Re: my $x = 100 for 1..3  why is $x undef <mgjv@tradingpost.com.au>
    Re: my $x = 100 for 1..3  why is $x undef <jihghong@yahoo.com.tw>
    Re: my $x = 100 for 1..3; why is $x undef (Charles DeRykus)
        Need Help : Passing Parameters to Functions (KP)
    Re: new Perl feature request: call into shared libs <nospam-abuse@ilyaz.org>
    Re: new Perl feature request: call into shared libs <para@tampabay.rr.com>
    Re: Posting more than 1 string from a file <matt307@carolina.rr.com>
    Re: Posting more than 1 string from a file (Jay Tilton)
    Re: Prefix matching for filenames? <wcitoan@NOSPAM-yahoo.com>
    Re: Slow garbage collection of bigass hash? <goldbb2@earthlink.net>
        Sorting in Perl <anandks@optonline.net>
    Re: Sorting in Perl <goldbb2@earthlink.net>
    Re: Sorting in Perl <peakpeek@purethought.com>
    Re: Sorting in Perl (Charles DeRykus)
    Re: sorting woes <bigj@kamelfreund.de>
    Re: sorting woes <krahnj@acm.org>
        Using filehandles with compare <oxmard.Rules@ab.ab>
    Re: Using filehandles with compare <bwalton@rochester.rr.com>
    Re: Using filehandles with compare <oxmard.Rules@ab.ab>
    Re: Using filehandles with compare <oxmard.Rules@ab.ab>
    Re: Using filehandles with compare <mgjv@tradingpost.com.au>
    Re: XS, SWIG? Accessing C API easily <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 11 Mar 2003 22:22:47 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: dbm lock problem
Message-Id: <3E6EA807.891FF833@earthlink.net>

Vassilis Tavoultsidis wrote:
> 
> I am trying to lock a dbm file using the following code
[snip broken code]

Get from CPAN one of the following modules:
   DB_File::Lock
   Tie::DB_Lock
   Tie::DB_LockFile
   DB_File::Lock2

There are other lock thingies not integrated with tied dbm files,
though.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Wed, 12 Mar 2003 03:25:29 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: dbm lock problem
Message-Id: <mo9t6v497gl88an50qoep754vfbfmk38l5@4ax.com>

On Tue, 11 Mar 2003 14:29:00 +0200, in comp.lang.perl.misc, "Vassilis Tavoultsidis" <ixanthi@ixan-remove
this-hi.gr> wrote:

>I am trying to lock a dbm file using the following code
>
>#!/usr/bin/perl
>
>use CGI;
>use Fcntl;
>use DB_File;
>
>my $q = new CGI;
>
>
>$dbfile = $q->param("dbfile");
>
>print "Content-type: text/html\n\n";
>
>print $dbfile."<br>";
>
>local *DBM;
>my $db = tie %dbdata, "DB_File", $dbfile, O_CREAT | O_RDWR, 0755 or print
>"could not tie to $dbfile: $!";
>my $fd = $db->fd;
>open DBM, "+<&=$fd" or print "Could not dub DBM for lock : $!";
>flock DBM, LOCK_EX;
>undef $db;
>
>while (($k, $v) = each(%dbdata))
>{
>  print $k."::".$v."<br>";
>};
>print "end.";
>untie %dbdata;
>exit;
>
>I am not taking an error messages but it seems that nothing is being loaded

There is a note in the DB_File documentation about this:

perldoc DB_File

 HINTS AND TIPS
 Locking: The Trouble with fd
 ...

You need to use BerkeleyDB.pm or one of Tie::DB_Lock, 
Tie::DB_LockFile, DB_File::Lock


>Should I use the dbmopen and dbmclose procedures everything works fine but I
>have no locking capabilities

No

-- 
Sharon


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

Date: Wed, 12 Mar 2003 02:17:34 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Forcing format to print top of page
Message-Id: <2Nwba.120034$gf7.26215857@news4.srv.hcvlny.cv.net>


"gavs" <gavspp@yahoo.com> wrote in message
news:54dc4b2a.0303111316.9e21605@posting.google.com...
> Hello:
>
> I am creating a report which should print the top of page every time
> the id changes, regardless of the number of lines used.
>
> Here is the code.  Can you please point out my mistake?  Thanks for
> your help!
>
> gavs.
>
> #!/usr/bin/perl
>
> $= = 45;
>
> while (fetching results from db) {
>
>  if ($new_id != $cur_id) {
>       $new_id = $cur_id;
>       ##$% = 46;
>       $- = 0;
>    }
>
>
> write(OUTFILE);
> }
>
> format OUTFILE_TOP=
> .
> .
> .
>
> format OUTFILE=
> .
> .
> .
>
> close OUTFILE;


Your pseudo code is correct.  I suspect that the if block is never
executed due to an error in the code that you have not shown.
(Temporarily add a print statement to the if block to check this.)  I
probably could be of more help if you provided a small working program
that demonstrates the problem.

I usually advise against using write/format because it is difficult and
not well documented.  Your use of headers may well be an exception where
the benefit is worth the pain.

Good Luck,
Bill




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

Date: Tue, 11 Mar 2003 17:08:22 -0600
From: Mandrake <Mandrake@dream-server.com>
Subject: Re: Letting users change their password via web form...
Message-Id: <v6sr36s6mibefe@news.supernews.com>

Ahhh, thanks for that tidbit of advice there Abigail. That means that if I 
don't know how to build an automobile that I shouldn't drive one, correct? 
If I don't know how to build a plane, maybe I shouldn't fly? Actually what 
you're saying is that you don't have the time or the ability to explain, 
and that I should go find what I'm looking for elsewhere. Thanks for your 
time (NOT), it has done me well </sarcasm>.

-- 
Take care,
Randall

Abigail wrote:

> Mandrake (Mandrake@dream-server.com) wrote on MMMCDLXXIX September
> MCMXCIII in <URL:news:v6qvh3eup6hbcb@news.supernews.com>:
> ""  Hi guys. Anyone have a suggestion as to what I can use to allow users
> to
> ""  change their own passwords? I tried the Expect version, and
> unfortunately I
> ""  don't have time to learn another language so that I can have the
> script
> ""  work with the CGI script when they argue over the users password being
> too
> ""  short, the same, etc. I tried downloading 'poppassd', and it appears
> to be
> ""  grossly out of date (I grab the modules it needs, and when I try it,
> it
> ""  gives me the error 'Your vendor has not defined Socket macro
> ""  require_version, used at /usr/lib/perl5/site_perl/5.6.1/LWP/Socket.pm
> line
> ""  45'). I *KNOW* that there are other system admins sitting around out
> there
> ""  who have developed this, because it's sort of inconceivable to think
> that
> ""  all system administrators manually change the passwords for all of
> their
> ""  users. I can deal with the security part of it (checking the previous
> ""  password, making sure they're not slipping in something they
> shouldn't,
> ""  etc.), but it's just getting old trying to find such a useful program
> which
> ""  appears to not exist.
> 
> 
> Changing passwords over the web is dangerous. My standpoint is that
> if you can't figure out how to do it, you're not qualified enough
> to do it.
> 
> 
> 
> Abigail



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

Date: 11 Mar 2003 19:27:32 -0800
From: flateyjarbok@yahoo.com (R Solberg)
Subject: LWP with cookie and Form not working
Message-Id: <386cc483.0303111927.5b2a83e7@posting.google.com>

Hi,
I need some advice or anything you can do to help me solve this. Can't
get this program to output anything.  It runs without an error message
and nothing happens.  Trying to pull information from a web site page.
target URL =http://online.wsj.com/documents/mktindex.htm?diaries.htm

Thanks much,
Richard




use strict;
use HTTP::Request::Common;
use HTML::Form;
use LWP::UserAgent;
use HTTP::Cookies;
use FileHandle;


my $ua = LWP::UserAgent->new();

$ua->agent("Automation/0.1");
$ua->cookie_jar(
  HTTP::Cookies->new( autosave => 1 ));

my $request = $ua->request( POST
'http://online.wsj.com/login?URI=%2Fdocuments%2Fmktindex.htm?diaries.htm');

my $form = HTML::Form->parse( $request->content, $request->base());

print $form->dump;
$form->value( 'Login',   "myuseridhere" );
$form->value( 'Password', "mypassword" );
print $form->dump;

my $response = $ua->request( $form->click() );
$response = $ua->request(GET
'http://online.wsj.com/documents/mktindex.htm?diaries.htm');


my @outputLines = split(/\n/, $response->content);

my $outputFileHandle = new FileHandle;
$outputFileHandle->open(">c:\\temp.txt");

foreach my $line (@outputLines)
{
   print $outputFileHandle $line;
}
$outputFileHandle->close;


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

Date: 12 Mar 2003 03:47:30 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Merging log files using hash - good idea/possible?
Message-Id: <1047440847.128964@elaine.furryape.com>

In article <b4j0ro$ic14@onews.collins.rockwell.com>,
Michael Carman  <mjcarman@mchsi.com> wrote:
>Better to convert it to a true time string. There are lots of modules on
>CPAN to do this sort of thing. (Date::Calc, Date::Manip, etc.)

When assisting someone with the identical problem, I helped her
get much better performance by using Memoize.



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

Date: Wed, 12 Mar 2003 02:37:13 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: my $x = 100 for 1..3  why is $x undef
Message-Id: <slrnb6t7ap.79p.mgjv@verbruggen.comdyn.com.au>

On 11 Mar 2003 20:43:13 GMT,
	Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> Anno Siegel wrote in comp.lang.perl.misc :
>> 
>>     my $x = 100 for 1 .. 3;
>>     print defined $x? $x: '<undef>';

> May I quote the relevant part of perlsub ?
> 
>     B<NOTE:> The behaviour of a C<my> statement modified with a statement
>     modifier conditional or loop construct (e.g. C<my $x if ...>) is
>     B<undefined>.  The value of the C<my> variable may be C<undef>, any
>     previously assigned value, or possibly anything else.  Don't rely on
>     it.  Future versions of perl might do something different from the
>     version of perl you try it out on.  Here be dragons.

Ah. I _knew_ I had seen this somewhere. I also vaguely remembered some
p5p discussions on this, but couldn't find them.

This, of course, is rather new in perlsub.pod (It appeared in 5.8.0),
and arguably is in the wrong spot, especially since there is no use of
a statement modifier anywhere near this note. I don't think that perlsub is
really the correct spot to comment on this "odd" behaviour of
statement modifiers, which are all discussed in perlsyn.pod.

Maybe perlsyn should have a reference to this, or this block should be
moved to perlsyn, and a reference to the new position inserted here.

Any comments? If not, I'll submit a doc patch.

Martien
-- 
                        | 
Martien Verbruggen      | Useful Statistic: 75% of the people make up
Trading Post Australia  | 3/4 of the population.
                        | 


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

Date: Wed, 12 Mar 2003 10:47:22 +0800
From: "John Lin" <jihghong@yahoo.com.tw>
Subject: Re: my $x = 100 for 1..3  why is $x undef
Message-Id: <b4m74f$mg4@netnews.hinet.net>

"Anno Siegel" wrote
> Rafael Garcia-Suarez wrote in comp.lang.perl.misc:
> > Anno Siegel wrote in comp.lang.perl.misc :

> > >     my $x = 100 for 1 .. 3;
> > >     print defined $x? $x: '<undef>';

> > B::Deparse can't deparse the strict pragma correctly, it only recognizes
> > the strict-refs subpragma. The result you get is not surprising.

> >     B<NOTE:> The behaviour of a C<my> statement modified with a statement
> >     modifier conditional or loop construct (e.g. C<my $x if ...>) is
> >     B<undefined>.

> Ah, there it is.  Thanks for the pointer.  So it falls into the same
> class as the once-popular "my $x if 0".

Ah...  So the logic is like this (as followed), right?

1. It is not a bug of "use strict", because "my $x" is in the same scope as "print $x".

According to 1. the answer is expected to be $x == 100, but

2. The behaviour of "my ... with a modifier" is undefined.
    So we may get a result of undefined $x.
    This is acceptable because it is documented.

3. As for Deparse, its deparsed program is only logically equivalent to the original
    program but the scoping is not.  The assessment "no extra scope" is still correct.

If the above conclusions are right, IMHO no bug report is needed.

Thank you and best regards.
John Lin

P.S.  Comments on 3.  I think it is impossible for Deparse to output a
totally (scoping and executing) equivalent deparsed program for the O.P. program.

For example:

my $x;
foreach $_ (1 .. 3) {
    $x = 100;
}
print defined $x? $x: '<undef>';

Is NOT an equivalent one.  Scoping is OK, but execution is not.
In the O.P. program, "my" is executed three times.  But only one time here.

For another example:

foreach $_ (1 .. 3) {
    my $x = 100;
}
print defined $x? $x: '<undef>';

Execution is equivalent, but scoping is not (our conclusion is "no extra scope").

Since "totally equivalent" is impossible,
that's why I consider conclusion 3. as acceptable.




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

Date: Wed, 12 Mar 2003 03:11:27 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: my $x = 100 for 1..3  why is $x undef
Message-Id: <slrnb6t9av.79p.mgjv@verbruggen.comdyn.com.au>

On Wed, 12 Mar 2003 10:47:22 +0800,
	John Lin <jihghong@yahoo.com.tw> wrote:
> "Anno Siegel" wrote
>> Rafael Garcia-Suarez wrote in comp.lang.perl.misc:
>> > Anno Siegel wrote in comp.lang.perl.misc :
> 
>> > >     my $x = 100 for 1 .. 3;
>> > >     print defined $x? $x: '<undef>';
> 
>> > B::Deparse can't deparse the strict pragma correctly, it only recognizes
>> > the strict-refs subpragma. The result you get is not surprising.
> 
>> >     B<NOTE:> The behaviour of a C<my> statement modified with a statement
>> >     modifier conditional or loop construct (e.g. C<my $x if ...>) is
>> >     B<undefined>.
> 
>> Ah, there it is.  Thanks for the pointer.  So it falls into the same
>> class as the once-popular "my $x if 0".
> 
> Ah...  So the logic is like this (as followed), right?
> 
> 1. It is not a bug of "use strict", because "my $x" is in the same
> scope as "print $x".

No.

It is not a bug, because it is documented to result in undefined
behaviour. In other words, what those constructs do cannot be
predicted reliably, and what they do in your version of Perl today,
should not be relied on for any other platform or perl version.

The term "undefined behaviour" is one well-known in the world of C
programmers, although it is fairly new in Perl. The language Perl used
to simply be defined by the behaviour of its only implementation,
perl. Obviously, on this point, the p5p decided that whatever the
current behaviour was, it should not define the _correct_ behaviour.

> According to 1. the answer is expected to be $x == 100, but
> 
> 2. The behaviour of "my ... with a modifier" is undefined.
>     So we may get a result of undefined $x.
>     This is acceptable because it is documented.

I think you're confusing some things. The statement above does not say
that $x could become undefined, but that the result of that code is
undefined as a whole. Perl might refuse to compile it, or it may
introduce secret, odd scopes, or it may crash at runtime (although
that would probably be a bug).

So, that note does not say that $x is ok to be undefined after such a
statement, but that that statement should not be used, because the
results are undefined, i.e. unpredictable.


> 3. As for Deparse, its deparsed program is only logically equivalent
> to the original program but the scoping is not.  The assessment "no
> extra scope" is still correct.
> 
> If the above conclusions are right, IMHO no bug report is needed.

I don't think a bug report is needed (except maybe a doc patch to move
the note to a more appropriate spot), simply because the documentation
specifically states that you cannot expect sane results when using
this construction.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | values of Beta will give rise to dom!
                        | 


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

Date: Wed, 12 Mar 2003 11:38:50 +0800
From: "John Lin" <jihghong@yahoo.com.tw>
Subject: Re: my $x = 100 for 1..3  why is $x undef
Message-Id: <b4ma4d$e72@netnews.hinet.net>

"Martien Verbruggen" wrote
> John Lin wrote:

> > 1. It is not a bug of "use strict", because "my $x" is in the same
> > scope as "print $x".

> No.
> It is not a bug, because it is documented to result in undefined behaviour.

Now I understand.  Its hehaviour is undefined.  So we cannot say
either "in the same scope", nor "in different scopes".  Because it is "undefined".

Thank you.
John Lin




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

Date: Tue, 11 Mar 2003 23:42:18 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: my $x = 100 for 1..3; why is $x undef
Message-Id: <HBLz6I.BKy@news.boeing.com>

In article <slrnb6shfh.kfn.abigail@alexandra.abigail.nl>,
Abigail  <abigail@abigail.nl> wrote:
>Charles DeRykus (ced@bcstec.ca.boeing.com) wrote on MMMCDLXXIX September
>MCMXCIII in <URL:news:HBKKMv.23D@news.boeing.com>:
>[]  
>[]  But doesn't perlsyn imply a scope ... ("The foreach modifier 
>[]  evaluates once for each element in its LIST, with $_ aliased 
>[]  to the current element") ?
>
>
>Where do you read the word 'scope' or anything related to that in the
>part you quote?
>

I didn't -- so I said 'imply'. This thread, especially the
cited cautionary note in persub about 'my', clearly lays to 
rest inferences about scope.   

[Seems like a repetitive mention of this subtlety in perlsyn might be 
good IMO].

--
Charles DeRykus 



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

Date: 11 Mar 2003 15:27:51 -0800
From: snazystyl@hotmail.com (KP)
Subject: Need Help : Passing Parameters to Functions
Message-Id: <dc2b0830.0303111527.39d08ba9@posting.google.com>

In FirstSub $FileList is present but in the Second Sub it is not. This
then returns a Error because it's not in the SecondSub. How would I
pass $filelist to the SecondSub so that it can be used there as well.
I have been reading up on Passing Parameters to Functions. But I'm
just not getting it. Any help would be greatly appreciated.

sub FirstSub
{
    my $filelistexts; 
    my $fileinfo;
    my $FileList;  
    if (exists $ENV{'SYSTEMROOT'})
    {
        my $xmlfile = $ENV{"SYSTEMROOT"}.$g_xmlfilepath;
        open (FILE, $xmlfile) || die;

        while ($fileinfo = <FILE> )
        {
            if ($fileinfo =~ /.*<EXTENSIONS>.*/)
            {
                while ($filelistexts = <FILE>)
                {
                        if ($filelistexts =~ /<REC>(.*)<\/REC>/)
                        {
                        $FileList = $FileList .';'. $1;
                        }
                }last;
            }
        }
    }
    else
    {
    die;
    }
}

sub SecondSub
{
    my $extleftover;
    my $NotFoundList;
    my @SystemList = split/;/, $SystemList; 
    
    foreach $extleftover (@SystemList)
    {	
        unless ($FileList =~ m/.*;\Q$extleftover\E;.*/) 
  	{
  	$NotFoundList = $NotFoundList .$extleftover.';';
  	}
    }
}
  
Thanks,
  KP


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

Date: Tue, 11 Mar 2003 23:09:06 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <b4lqai$q3r$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Matt Taylor
<para@tampabay.rr.com>], who wrote in article <vacba.19122$Xu4.533273@twister.tampabay.rr.com>:

> Default convention (__cdecl) is the same. Windows system libraries are
> compiled with __stdcall convention which is different. The following code
> should suffice for any convention except a register-parameter scheme:

Actually, one could also duplicate the last min(3, num_params)
arguments in EAX, EDX, ECX.  This way the same code could call
__regparam__(3) functions too.

The call will be transparent for functions with up to 3 arguments; to
call __regparam__(3) functions with more than 3 arguments one would
need to move the first 3 arguments to the end of the list.

Not convenient, but at least it would be *possible* to call functions
with most usual the calling conventions.

>  mov [ecx], eax
> 
>  ; If 64-bit return value, also do next line
>  ; mov [ecx+4], edx

I think it is convenient to make this unconditional; let the caller
worry about what to do with retval[1]...

Thanks,
Ilya





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

Date: Wed, 12 Mar 2003 02:04:09 GMT
From: "Matt Taylor" <para@tampabay.rr.com>
Subject: Re: new Perl feature request: call into shared libs
Message-Id: <tAwba.42682$lW3.1054173@twister.tampabay.rr.com>

"Ilya Zakharevich" <nospam-abuse@ilyaz.org> wrote in message
news:200303112309.PAA23983@powdermilk.math.berkeley.edu...
> [A complimentary Cc of this posting was sent to
> Matt Taylor
> <para@tampabay.rr.com>], who wrote in article
<vacba.19122$Xu4.533273@twister.tampabay.rr.com>:
>
> > Default convention (__cdecl) is the same. Windows system libraries are
> > compiled with __stdcall convention which is different. The following
code
> > should suffice for any convention except a register-parameter scheme:
>
> Actually, one could also duplicate the last min(3, num_params)
> arguments in EAX, EDX, ECX.  This way the same code could call
> __regparam__(3) functions too.


And wouldn't be portable across OSes, possibly not even libraries since you
can change the allocation order. A couple years ago I ported some stuff from
Watcom/Masm to DJGPP/Nasm. Rather than rewriting some of the assembly, I
used the regparm modifier with another that changed allocation order. I hope
this isn't commonplace, but it's an exception to the rule.

Other register parameter schemes are like this, too. I believe (not sure)
old Watcom stuff used ebx as a general register and would pass parameters in
ebx. Some compilers differ on order. It's really a mess to link with
register-parameter conventions.

> The call will be transparent for functions with up to 3 arguments; to
> call __regparam__(3) functions with more than 3 arguments one would
> need to move the first 3 arguments to the end of the list.
>
> Not convenient, but at least it would be *possible* to call functions
> with most usual the calling conventions.


In a platform-specific environment it would be possible.

> >  mov [ecx], eax
> >
> >  ; If 64-bit return value, also do next line
> >  ; mov [ecx+4], edx
>
> I think it is convenient to make this unconditional; let the caller
> worry about what to do with retval[1]...

Probably.

-Matt




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

Date: Wed, 12 Mar 2003 00:20:44 GMT
From: matt307 <matt307@carolina.rr.com>
Subject: Re: Posting more than 1 string from a file
Message-Id: <3E6E7D56.9A97DEDF@carolina.rr.com>

sorry i am very new to perl so i dunno what i am supposed to do to get help.

anways:::

#!/usr/local/bin/perl


  open (MESSAGE, "<messages.txt");
  @pastmessages = <MESSAGE>;
  close (MESSAGE);

  $count=1;

  foreach $message (@pastmessages) {

this is what is at the top of the script, then later on where i want the messages
to be posted i have this:

<font color="#FFCC00">$message</font>\n<hr>

and finally at the end of the script before i close off the html is:

$count++;

}

i dunno if this is right or what.  and sorry again about all that stuff.



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

Date: Wed, 12 Mar 2003 02:30:45 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Posting more than 1 string from a file
Message-Id: <3e6e97cd.20265675@news.erols.com>

matt307 <matt307@carolina.rr.com> wrote:

: sorry i am very new to perl so i dunno what i am supposed to do to get help.

The posting guidelines contain a great wealth of tips on writing
articles that will be cooperatively received.

http://mail.augustmail.com/~tadmc/clpmisc.shtml

: #!/usr/local/bin/perl
:   open (MESSAGE, "<messages.txt");

Always check the return value of open() for success.

    open (MESSAGE, "<messages.txt")
        or die "Cannot open 'messages.txt' for read: $!";

:   @pastmessages = <MESSAGE>;
:   close (MESSAGE);
:   $count=1;

Does $count have a purpose?

:   foreach $message (@pastmessages) {
: 
: this is what is at the top of the script, then later on where i want the messages
: to be posted i have this:
: 
: <font color="#FFCC00">$message</font>\n<hr>

I have to assume that's inside a <<HERE doc, and there's a print() for
it.

: and finally at the end of the script before i close off the html is:
: 
: $count++;
: }
: 
: i dunno if this is right or what.  and sorry again about all that stuff.

Style points aside (package variables instead of lexicals, slurping
the file contents), it looks swell.

Only two things seem possible causes the difficulty.

1) messages.txt contains only one message.  What's the code that
writes this file look like?

2) There's a "last" statement somewhere in that foreach block.



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

Date: Wed, 12 Mar 2003 00:44:32 -0000
From: "W. Citoan" <wcitoan@NOSPAM-yahoo.com>
Subject: Re: Prefix matching for filenames?
Message-Id: <slrnb6t0ne.24v.wcitoan@wcitoan-via.supernews.com>

On 10 Mar 2003 23:27:07 -0800, jtd wrote:
>  
>  You're right, I'd forgotten that the list is not sorted. Looks like I
>  might have to use Berkeley db after all...

Why?  Are you worried about performance?  You can just glob on the
filename pattern (*.dat if I remember your post right) and sort it
within perl.

- W. Citoan
-- 
Youth.  It's a wonder that anyone ever outgrows it.


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

Date: Tue, 11 Mar 2003 22:11:21 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Slow garbage collection of bigass hash?
Message-Id: <3E6EA559.5A593CF7@earthlink.net>

Seth Brundle wrote:
> Seth Brundle wrote:
> > I have a subroutine which creates a 400MB hash.
> >
> > I propogate it with about 2.2M key/value pairs, run some ops on it,
> > it works fine.
> >
> > When the hash falls out of scope or when I try to explicitly undef
> > it, or try to assign () to it, the program just hangs. It has hung
> > for at least 10 minutes before I killed it, I've never seen it
> > complete.
> >
> > I have never seen this behavior from Perl before - then again, I've
> > never built a 400MB hash before.
> >
> > Any ideas?
> 
> I just fixed this by recompiling to use the malloc which comes with
> Perl.
> Wacky.

When the hash goes out of scope, perl frees it.  When you free the hash,
each of the keys and values get freed, using either Perl_free() or
free(), depending on whether you've compiled with perl's malloc or not.

With some versions of libc, each call to free() tries to merge the
released block of memory with an adjacent block of memory (thus, instead
of two seperate items in its freelist, there's a single larger item). 
This reduces fragmentation (meaning that latter malloc() calls will be
faster, and the process's total size will be smaller), but it takes time
to do.  With thousands of little bits of data being released, each one
takes time, and it adds up.

Note that this kind of defragmentation isn't *always* slow, but with
some versions of free(), it requires a *search* to see if there are any
adjacent blocks to merge with, instead of taking constant time.  This is
where the major slowdown comes from.

AFAIK, perl doesn't merge freed blocks like that (or if it does, it does
so efficiently).  As a result, freeing thousands of bits of data doesn't
take quite so long.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Wed, 12 Mar 2003 03:47:06 GMT
From: "Anand Kandasamy" <anandks@optonline.net>
Subject: Sorting in Perl
Message-Id: <_4yba.120883$gf7.26560897@news4.srv.hcvlny.cv.net>

Hello,

I have four huge arrays (22986152 data points to be exact) and I need
to sort this array. The code I have chokes and the program dies. I am
using "sub bynumber { $a <=> $b; } " to sort. Is there a limit on
the data set ? Or is there any other sort methods that I can use, that
can handle data sets this large and sometimes even more.

The current code is trying to run on a Dual PIII 1.6 GHz w/1GB.

Thanks

Anand




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

Date: Tue, 11 Mar 2003 23:57:40 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Sorting in Perl
Message-Id: <3E6EBE44.57F580A5@earthlink.net>



Anand Kandasamy wrote:
> 
> Hello,
> 
> I have four huge arrays (22986152 data points to be exact) and I need
> to sort this array.

The number 22986152 is 0x015E_BDA8 hex.

If this are integers, and if this were C, then each element of your
array would be taking up 0x057AF6A0 bytes.  But each array element is a
perl scalar -- if they're ints, that's about 32 bytes (due to malloc
padding... plus there might be other malloc overhead), for a total of
0x2BD7_B500 bytes.

This is pretty huge -- within a factor of 8 of 2**32.  If you only have
32-bit pointers, it's possible that you can't address that much memory.

> The code I have chokes and the program dies. I am
> using "sub bynumber { $a <=> $b; } " to sort. Is there a limit on
> the data set ?

You are limited to perl's memory.

> Or is there any other sort methods that I can use, that
> can handle data sets this large and sometimes even more.

You can recompile perl to use larger pointers, or replace the use of an
array with a string (accessed by vec()), or tie your array to a disk
file.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Wed, 12 Mar 2003 04:45:06 +0000
From: Sharon Grant <peakpeek@purethought.com>
Subject: Re: Sorting in Perl
Message-Id: <jjet6v874kks5oa1vqt4u38qnk5dj554kn@4ax.com>

On Wed, 12 Mar 2003 03:47:06 GMT, in comp.lang.perl.misc, "Anand Kandasamy" <anandks@optonline.net> wrote:

>I have four huge arrays (22986152 data points to be exact) and I need
>to sort this array. The code I have chokes and the program dies. I am
>using "sub bynumber { $a <=> $b; } " to sort. Is there a limit on
>the data set ? Or is there any other sort methods that I can use, that
>can handle data sets this large and sometimes even more

You could use DB_File to store the data in a Berkeley/DB 
btree database. Berkeley/DB will sort the data as you load 
it into the database

-- 
Sharon


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

Date: Wed, 12 Mar 2003 04:44:14 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Sorting in Perl
Message-Id: <HBMD5q.91E@news.boeing.com>

In article <_4yba.120883$gf7.26560897@news4.srv.hcvlny.cv.net>,
Anand Kandasamy <anandks@optonline.net> wrote:
>Hello,
>
>I have four huge arrays (22986152 data points to be exact) and I need
>to sort this array. The code I have chokes and the program dies. I am
>using "sub bynumber { $a <=> $b; } " to sort. Is there a limit on
>the data set ? Or is there any other sort methods that I can use, that
>can handle data sets this large and sometimes even more.
>

If memory's the problem, you may want to try a disk sort. Take a 
look at the DB_File with  a DB_TREE file type.

--
Charles DeRykus


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

Date: Wed, 12 Mar 2003 00:05:49 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: sorting woes
Message-Id: <pan.2003.03.11.23.04.47.71003@kamelfreund.de>

Johannes Fürnkranz wrote at Tue, 11 Mar 2003 19:53:31 +0100:

> Janek Schleicher wrote:                  ^^
>> 
>> You had to write
>> <>

Erm, sorry,
I meant <=> of course.

>> for the comparison operator instead of only a <.
> 
> Oh my god. I can't believe that this cost me almost the whole afternoon...

That's programming :-(


Cheerio,
Janek


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

Date: Wed, 12 Mar 2003 03:41:10 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: sorting woes
Message-Id: <3E6EAC43.85CF42D5@acm.org>

Johannes Fürnkranz wrote:
> 
> I'm sure there is a most trivial bug in this program, but I just can't
> find it.
> 
> I make a list of $l random numbers, than I make pairs [ $_, $random[$i]
> ], and then I want to sort this list by the second item.
> (I could write this more concisely, of course, but this is part of a
> bigger thing).

If you just need to rearrange an array in random order then see the FAQ:

perldoc -q shuffle


> Can anybody tell me, why it doesn't sort the values (or better why they
> get sorted in a weird way?
> 
> ---Code starts here---
> use strict;
> 
> my $l = 10;  # length of list
> my @random = map rand, (1..$l);
> 
> sub list_sort {
>    my @h = ();
>    foreach (0..$l-1) {
>      push @h, [$_, $random[$_]];
>    }
>    return sort { $a->[1] < $b->[1] } @h;
> }
> 
> map { printf "$_: %5.4f\n", $random[$_] } (0..$l-1);
> print "\n";
> map { printf "$_->[0]: %5.4f\n", $_->[1] } list_sort;
> print "\n";

Ick!  map in void context.

printf "%d: %5.4f\n" x $l, map( @$_, @random );
print "\n";
printf "%d: %5.4f\n" x $l, map( @$_, list_sort );
print "\n";



John
-- 
use Perl;
program
fulfillment


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

Date: Tue, 11 Mar 2003 18:35:22 -0600
From: "Peter Shankey" <oxmard.Rules@ab.ab>
Subject: Using filehandles with compare
Message-Id: <mEqdndqI_c5UHfOjXTWcqQ@comcast.com>

It seems filehandles are not working as I would expect. What am I missing,
is it a bug?.
here is the script:

use Strict;
use warnings;
use File::Compare;

($,,$\) = (" ","\n");

my $return = compare("c:/t/d1/test1.txt","c:/t/d2/test1.txt");
print ("return is:", $return);

if ((compare("c:/t/d1/test1.txt","c:/t/d2/test1.txt") == 0)){
 print ("files are the same");
} else {
 print("files are not the same");
}

open(FH1,"c:/t/d1/test1.txt") || die "could not open $!";
open(FH2,"c:/t/d2/test1.txt") || die "could not open $!";

if ((compare(FH1,FH2) == 0)){
 print ("files are the same");
} else {
 print("files are not the same");
}

close(FH1);
close(FH2);

Assuming the files are the same:
#
#
# perl compare.pl
return is: 0
files are the same
files are not the same

#

Assuming the files are different:
#
# perl compare.pl
return is: 1
files are not the same
files are not the same

#
#
#
#
# perl -V
Summary of my perl5 (revision 5 version 8 subversion 0) configuration:
  Platform:
    osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
    uname=''
    config_args='undef'
    hint=recommended, useposix=true, d_sigaction=undef
    usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cl', ccflags
='-nologo -Gf -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE
_DES_FCRYPT  -DPERL_IMPLICIT_CONTEX
T -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
    optimize='-MD -Zi -DNDEBUG -O1',
    cppflags='-DWIN32'
    ccversion='', gccversion='', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='link', ldflags
'-nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:\Perl\lib\CORE"  -ma
chine:x86'
    libpth="C:\Perl\lib\CORE"
    libs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib msvcrt.lib
    perllibs=  oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32
 .lib  netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib msvcrt.lib
    libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
    gnulibc_version='undef'
  Dynamic Linking:
    dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ',
lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf  -libpath:"C:\Perl
\lib\CORE"  -machine:x86'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
  Locally applied patches:
        ActivePerl Build 805
  Built under MSWin32
  Compiled at Feb  4 2003 18:08:02
  @INC:
    C:/Perl/lib
    C:/Perl/site/lib
    .

#






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

Date: Wed, 12 Mar 2003 02:01:46 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Using filehandles with compare
Message-Id: <3E6E9501.3050008@rochester.rr.com>

Peter Shankey wrote:

 ...
> if ((compare(FH1,FH2) == 0)){

Try:

   if ((compare(*FH1,*FH2) == 0)){

You should also note that compare may also return -1 in the event of an 
error.  It would be good to also test for that.
-- 
Bob Walton



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

Date: Tue, 11 Mar 2003 20:45:39 -0600
From: "Peter Shankey" <oxmard.Rules@ab.ab>
Subject: Re: Using filehandles with compare
Message-Id: <qz2dnWWnI8nIAvOjXTWcqw@comcast.com>


"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3E6E9501.3050008@rochester.rr.com...
> Peter Shankey wrote:
>
> ...
> > if ((compare(FH1,FH2) == 0)){
>
> Try:
>
>    if ((compare(*FH1,*FH2) == 0)){
>
> You should also note that compare may also return -1 in the event of an
> error.  It would be good to also test for that.
> --

Thank you for the idea Bob I will try it. What is the * and where can I find
it in perldocs?




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

Date: Tue, 11 Mar 2003 21:08:08 -0600
From: "Peter Shankey" <oxmard.Rules@ab.ab>
Subject: Re: Using filehandles with compare
Message-Id: <_hednZF5TvcHOfOjXTWcqQ@comcast.com>


"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3E6E9501.3050008@rochester.rr.com...
> Peter Shankey wrote:
>
> ...
> > if ((compare(FH1,FH2) == 0)){
>
> Try:
>
>    if ((compare(*FH1,*FH2) == 0)){

using the * did the trick however, now I need to figure out what the * does.




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

Date: Wed, 12 Mar 2003 03:12:40 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Using filehandles with compare
Message-Id: <slrnb6t9d8.79p.mgjv@verbruggen.comdyn.com.au>

On Tue, 11 Mar 2003 20:45:39 -0600,
	Peter Shankey <oxmard.Rules@ab.ab> wrote:
> 
> "Bob Walton" <bwalton@rochester.rr.com> wrote in message
> news:3E6E9501.3050008@rochester.rr.com...
>> Peter Shankey wrote:
>>
>> ...
>> > if ((compare(FH1,FH2) == 0)){
>>
>> Try:
>>
>>    if ((compare(*FH1,*FH2) == 0)){

> Thank you for the idea Bob I will try it. What is the * and where can I find
> it in perldocs?

It's a glob, and you can read about them in the perlref documentation.

Martien
-- 
                        | 
Martien Verbruggen      | 
Trading Post Australia  | Curiouser and curiouser, said Alice.
                        | 


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

Date: Wed, 12 Mar 2003 02:57:13 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: XS, SWIG? Accessing C API easily
Message-Id: <slrnb6t8g9.79p.mgjv@verbruggen.comdyn.com.au>

[The OP's post hasn't showed up here, so I'm following up to this
one]

On 11 Mar 2003 21:20:01 GMT,
	Abigail <abigail@abigail.nl> wrote:
> Kelly Blakeland (kblang4-spam@spamgoawayar.com.au) wrote on MMMCDLXXVIII
> September MCMXCIII in <URL:news:3e6c6944$1_1@bn.ar.com.au>:
> ()  
> ()  I knew C quite well a while back, but have been completely spoiled
> ()  by Perl. I find that my C is now extremely hopeless.
> ()  
> ()  I don't want to write any C functions, but wish to use the C API
> ()  of various commercial products. Should I take the effort to
> ()  learn about SWIG, or try to learn XS?

It depends.

SWIG is nice in that it can be used for more than one language. It's
also better documented than XS, IMO. Both of them have tools that give
you a starting point when using a third party C API as a template to
create a Perl API. The real problem is not that, but the fact that a C
API directly made accessible to Perl often results in very
non-idiomatic calling signatures.

Did you have a look at the documentation at www.swig.org? They have
some articles there about using SWIG, specifically one about building
a Perl interface with SWIG.

Did you have a look at perlxstut and perlxs?

> ()  Does it work flawlessly, or am I going to find some C code which
> ()  simply can't be called from Perl? I know that most of the API calls
> ()  I'll need use pointers to various things, and maybe even more
> ()  complex things.

It'll probably work, but it'll also result in an ugly interface. Of
course, you can wrap the ugly interface in pure-perl and make that
accessible. 

A good reference on this sort of thing is /Extending and Embedding
Perl/ by Tim Jenness and Simon Cozens. It covers both XS and SWIG (and
Inline::C), and also goes into great detail about the Perl API, gives
guidelines and ways to make C APIs more Perl-like etc.

> ()  I'd hate to have to learn to write 40 separate interface declarations
> ()  for 40  C functions that I need, only to find that I can't call most
> ()  of these functions from Perl.

If there's only 40, I'd probably just let h2xs or swig do its job, and
write a pure Perl wrapper to translate the C API calling conventions
into something more palatable to the Perl programmer. This avoids you
having to know much about the guts of perl (perlguts) or its C API
(perlapi), although that never can hurt.

> You might want to consider Inline::C.

That's another possibility.

Martien
-- 
                        | 
Martien Verbruggen      | The world is complex; sendmail.cf reflects
Trading Post Australia  | this.
                        | 


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

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.  

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


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