[23976] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6177 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 22 09:05:36 2004

Date: Sun, 22 Feb 2004 06: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           Sun, 22 Feb 2004     Volume: 10 Number: 6177

Today's topics:
    Re: help on hash of hashes (Stephen Moon)
    Re: help on hash of hashes (Jay Tilton)
    Re: help on hash of hashes <gnari@simnet.is>
        Help with end of line charaters (Andy)
    Re: I wish buy Perl book <bart.lateur@pandora.be>
    Re: I wish buy Perl book <toylet_at_mail.hongkong.com>
        Newbie file / string question (Ren)
    Re: Newbie file / string question <noreply@gunnar.cc>
    Re: NEWBIE Question Subroutine help <gnari@simnet.is>
    Re: parsing data file into mysql table - help <invalid-email@rochester.rr.com>
    Re: parsing data file into mysql table - help <gnari@simnet.is>
        Questions on PAR <chatiman@free.fr>
    Re: Questions on PAR <calle@cyberpomo.com>
    Re: Replacing a text in multiple files with regular exp (Angel)
    Re: Simple code runs on linux, but not on windows -- wh <sgovindachar@yahoo.com>
    Re: Simple code runs on linux, but not on windows -- wh <noreply@gunnar.cc>
    Re: Simple code runs on linux, but not on windows -- wh <noreply@gunnar.cc>
    Re: The times() function and child cpu time misbehavior (A. Lewenberg)
    Re: trapping file i/o error <toylet_at_mail.hongkong.com>
    Re: trapping file i/o error <usenet@morrow.me.uk>
    Re: trapping file i/o error <tadmc@augustmail.com>
    Re: trapping file i/o error <toylet_at_mail.hongkong.com>
        why do i get this error? (dana livni)
    Re: why do i get this error? <gnari@simnet.is>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Feb 2004 00:58:10 -0800
From: vibfft@yahoo.com (Stephen Moon)
Subject: Re: help on hash of hashes
Message-Id: <9feadd98.0402220058.d3ff44a@posting.google.com>

Ben Morrow <usenet@morrow.me.uk> wrote in message news:<c1914h$du9$1@wisteria.csv.warwick.ac.uk>...
> vibfft@yahoo.com (Stephen Moon) wrote:
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> > news:<c18ang$8t9$1@mamenchi.zrz.TU-Berlin.DE>...
> > >
> > > Still using printf without a format.  I told you it's going to bite.
> > >
> > 
> > Well, I am a C programmer, so bear with me.  I takes a little while to
> > make a transition.
> 
> Even in C you should always printf("%s", string) rather than simply
> printf(string): otherwise you've got a security hole on your hands.
> What if you end up with string = "%d"?
> 
> Ben

i c. Of course, that's what I would if i were to write a C program.
I didn't understand what he meant by "using printf without a format."

What is a difference between using "print" and "printf"?  How would
you use "printf" with a format?  I am relatively new to perl.  Maybe
you can enlighten me.  So, you are telling me that

printf(DATA_OUT "$role=$HoH{$family}{$role}\n");

should be written as

printf(DATA_OUT "%s = %s\n", $role, $HoH{$family}{$role});

-Steve


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

Date: Sun, 22 Feb 2004 10:23:27 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: help on hash of hashes
Message-Id: <40388150.412173689@news.erols.com>

vibfft@yahoo.com (Stephen Moon) wrote:

: I didn't understand what he meant by "using printf without a format."
: 
: What is a difference between using "print" and "printf"?

Consult perlfunc for explanations of each function's purpose.

: How would
: you use "printf" with a format?  I am relatively new to perl.  Maybe
: you can enlighten me.  So, you are telling me that
: 
: printf(DATA_OUT "$role=$HoH{$family}{$role}\n");
: 
: should be written as
: 
: printf(DATA_OUT "%s = %s\n", $role, $HoH{$family}{$role});

Yes, that is the appropriate printf() statement.

More simply, change the printf() to an ordinary print().

    print( DATA_OUT "$role=$HoH{$family}{$role}\n" );



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

Date: Sun, 22 Feb 2004 10:08:38 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: help on hash of hashes
Message-Id: <c19v1k$haa$1@news.simnet.is>

"Stephen Moon" <vibfft@yahoo.com> wrote in message
news:9feadd98.0402220058.d3ff44a@posting.google.com...

> What is a difference between using "print" and "printf"?  How would
> you use "printf" with a format?  I am relatively new to perl.  Maybe
> you can enlighten me.  So, you are telling me that
>
> printf(DATA_OUT "$role=$HoH{$family}{$role}\n");
>
> should be written as
>
> printf(DATA_OUT "%s = %s\n", $role, $HoH{$family}{$role});

yes, or just
    print DATA_OUT "$role=$HoH{$family}{$role}\n";

gnari





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

Date: 22 Feb 2004 04:23:31 -0800
From: andy.westcott@motorola.com (Andy)
Subject: Help with end of line charaters
Message-Id: <52f64f3b.0402220423.f29006a@posting.google.com>

Hi,
I'm new to perl but need to write a script that takes a file and
formats lines.

The file has to 2 fields that are tab separated and each field is made
up of items separated by some type of linefeed character. The end of
the second field is identified by another type of linefeed character.

When I view the file in VIM the second linefeed shows as a ^M so there
must be a way of identifying these separately.

I have tried searching for \r \n  %CR %LF $VT $FF but nothing seems to
give the required effect.

I need to run the script on a PC. 

Please can you offer some advice or possible places to look.

Thanks

Andy


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

Date: Sun, 22 Feb 2004 09:26:56 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: I wish buy Perl book
Message-Id: <k7tg305sc3eu1k15gibml3ml4hs92erg6h@4ax.com>

James Willmore wrote:

>There are, however, a few book that are covered under an open source
>license - such as "Free as in Freedom".  However, I know of *NO* Perl book
>that is covered under an open source license.

No? What about "Beginning Perl" by SImon Cozens?

	<http://learn.perl.org/library/beginning_perl/>

And yes, that is an actual book:


<http://www.amazon.com/exec/obidos/tg/detail/-/1861003145/104-8031750-1312743?v=glance>

-- 
	Bart.


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

Date: Sun, 22 Feb 2004 21:48:20 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: Re: I wish buy Perl book
Message-Id: <4038b31a$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
> 
> No.  You should post the O'Reilly web site - since they already have a way
> to view books on line.  It's called Safari - and it's the *only* place to
> view O'Reilly books on line.

Or pay a visit to a library (be it online, public or private) and borrow 
a book. I think we could find Oreilly books in public libraries, right? :)


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


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

Date: 22 Feb 2004 05:33:25 -0800
From: rlpreston@sbec.com (Ren)
Subject: Newbie file / string question
Message-Id: <3602cff7.0402220533.3bd0d564@posting.google.com>

Suppose I have a file containing several lines like this:

:10000000E7280530AC00A530AD00AD0B0528AC0BE2

The data I want to extract are 8 hexadecimal strings, the first of
which is E728, like this:

:10000000 E728 0530 AC00 A530 AD00 AD0B 0528 AC0B E2

Also, the bytes in the string are reversed. The E728 needs to be 28E7,
0530 needs to be 3005 and so on.

I can do this in C++ and Pascal, but it seems like Perl may be more
suited for the task.

How is this accomplished using Perl?


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

Date: Sun, 22 Feb 2004 14:56:49 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie file / string question
Message-Id: <c1acrb$1ftf6d$1@ID-184292.news.uni-berlin.de>

Ren wrote:
> Suppose I have a file containing several lines like this:
> 
> :10000000E7280530AC00A530AD00AD0B0528AC0BE2
> 
> The data I want to extract are 8 hexadecimal strings, the first of 
> which is E728, like this:
> 
> :10000000 E728 0530 AC00 A530 AD00 AD0B 0528 AC0B E2
> 
> Also, the bytes in the string are reversed. The E728 needs to be
> 28E7, 0530 needs to be 3005 and so on.


     my @hex;
     while (<DATA>) {
         s/:\d{8}//;
         my @line = map { s/(..)(..)/$2$1/; $_ } /(\w{4})/g;
         push @hex, [ @line ];
     }
     print "@{$hex[0]}\n" for 0..$#hex;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sun, 22 Feb 2004 10:34:28 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: NEWBIE Question Subroutine help
Message-Id: <c1a0i3$hdo$1@news.simnet.is>

"Beable van Polasm" <beable+unsenet@beable.com.invalid> wrote in message
news:7xeksnoqhm.fsf@dingo.beable.com...
> "Dayton" <dayton500@NOSPAMhotmail.com> writes:
>
>
> >     print "<tr">\n";

and as a matter of style, I prefer not to put extra quotemarks
in example code posted on this group. they work best
in pairs.

gnari






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

Date: Sun, 22 Feb 2004 05:18:12 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: parsing data file into mysql table - help
Message-Id: <403839EB.4010301@rochester.rr.com>

smrtalec wrote:

> I have a script which function is to parse through a comma seperated data
> file, check if the entry is already existing, then if not enter the data
> into a mysql table. However, it only seems to be finding a match on the
> third time around.  ie if 'john brown' is in the data file it will only

--^^^^^


> recognise it as a match the second 'john brown'. It would almost seem the

------------------------------^^^^^^

This seems unclear:  is it the third time or the second time that the 
problem happens?  Or do you mean after the second time the name is 
inserted and the third time it is attempted to be looked up?  Also, the 
lookup you do is based on more than just the name -- does the address 
and city match also in your problem data?


> data from the previous row though inserted has not been registered. see code
> snippet below


Well, your example isn't complete enough to attempt to debug without 
putting much more work into it than I feel like doing.  So I'll just 
make some comments:


 ...
> #! /usr/bin/perl -w
> 
> use DBI;
> 

Missing "use strict;" -- let Perl give you all the help it can.


> 
> read_file();
> 
> sub insert_data {
>     my @$value = @_;

---------^^^^^^^
Does that actually work?  It doesn't in Perl version 5.8.0.  Are you 
running an ancient version of Perl, like 5.005?  What about DBI?  And 
mySQL?  If so, save yourself (and us) grief and upgrade.  Better would 
probably be:

       my $value=[@_];

But that is also awkward and tougher to understand than necessary.  Why 
not just pass around an array reference?


>     my $rdate=get_date();


What is get_date()?


>     my $p01=$dbh->quote ("0"); # own_id
>     my $p02=$dbh->quote ($rdate); # prop_date_lmod
> 
>     ...........repetive code removed.................
> 
>    my $p12=$dbh->quote ($value->[9]); # own_mobile_phone
>     my $sql = "INSERT INTO owner_info_inglewood
>                VALUES ($p01,$p02,$p03,$p04,$p05,$p06,
>                        $p07,$p08,$p09,$p10,$p11,$p12
>                       );";


It would be good to learn about and use placeholders here.  Then you 
wouldn't have to worry about all the quoting.


> 
>     my $sth_i = $dbh->prepare ($sql) or err_trap("failed to prepare
> statement\n");


If you use {RaiseError=>1} in your database connection, you can avoid 
all the awkward error checking.  And then you don't have to worry about 
missing one or trying to test them all somehow.


>     $sth_i->execute() or err_trap("failed to execute statement\n");
>     $sth_i->finish();


Why the call to finish()?  It probably does no harm, but is clearly not 
needed in this situation.  It is for SELECT statements that return 
multiple rows and are terminated early.


>     $dbh->commit() or err_trap("failed to execute statement\n");

commit??------------------------------------^^^^^^^


> }
> 
> sub verify_row {
>     my @$vrow = @_;

??-------^^^^^^-------see above


>     my $name_l =  $dbh->quote($vrow->[0]);
>     my $name_f =  $dbh->quote($vrow->[1]);
>     my $own_str_addr =  $dbh->quote($vrow->[4]);
>     my $own_city_addr = $dbh->quote($vrow->[5]);
>     ## query property info table to retrieve property id.
>     my $sql = ("SELECT own_name_l,own_name_f,
>                        own_str_addr,own_city_addr
>                 FROM owner_info_inglewood
>                 WHERE own_name_l LIKE $name_l
>                 AND own_name_f LIKE $name_f
>                 AND own_str_addr LIKE $own_str_addr
>                 AND own_city_addr LIKE $own_city_addr;"

>     or  err_trap('failed to prepare statement\n');


This "or" clause will never be executed, as the given string value will 
always be true.  And if it were executed, the error message would be 
misleading, as no prepare statement would have been involved.


>     my $sth_v = $dbh->prepare ($sql) or err_trap("failed to prepare
> statement\n");


sub err_trap isn't shown.  Does it die()?


>     $sth_v->execute or err_trap("failed to execute statement\n");


Does err_trap include the value of $dbh->errstr in the message it 
prints?  Hopefully so, as that will give the reason for the error.


>     my @own_name = $sth_v->fetchrow();


There is no "fetchrow" method in DBI (well, not documented, anyway). 
Perhaps you meant fetchrow_array?


>     $sth_v->finish();


If you're only fetching one row, you should probably call 
selectrow_array instead of the whole prepare...execute...fetch sequence. 
  Then the call to finish() would not be needed.  And the statement 
handle will effectively be finished anyway when the handle variable goes 
out of scope.


>     return @own_name;


You are returning an array here, and using it in the call as a scalar. 
This is technically OK, but usually one would expect call and returns to 
match in usage.


> 
> }
> 
> sub read_file {
>     my @own_name;
>     open (SDDB, "/home/rowan/perl/ho_info.csv") || die print "::$!\n";

huh?-------------------------------------------------^^^^^^^^^


>     $dbh = connect_try("rowan","******");


Odd logic here -- a sub named "read_file" also opens and closes a 
database.  Seems pretty misleading to me -- I wouldn't expect that side 
effect out of a sub with that name.

Also, you should declare:

    my $dbh;

back in your main program, as $dbh is intended to be in the scope of 
most of your subs.  For clarity (in my opinion), you should open and 
close the database there also, or call subs to do it from there.


>         while (<SDDB>) {
>             chomp $_;
>             my $row = [(split (/,/,$_))];
>             ## verify existance of property and retrieve property id.
>             unless (verify_row(@$row)) {


You sub verify_row returns an array.


>                 my  $frow = format_data(@$row);
>                 insert_data(@$frow);
>             }else{
>                 @own_name = verify_row(@$row);
>                 print "read_file::duplicate found   ->
> $own_name[0],$own_name[1],$own_name[2],$own_name[3]\n";
>                 print "read_file::duplicate original->
> $row->[0],$row->[1],$row->[4],$row->[5]\n";
>             }
>         }
>     $dbh->disconnect or err_trap("failed to disconnect statement\n");
>     close SDDB;
> }
> 
> sub connect_try {
>     my ($db_user,$db_password) = @_;
> my $dbh = DBI->connect("dbi:mysql:studio_3:67.**.**.**", "$db_user",

useless use of quotes--------------------------------------^--------^


> "$db_password",{AutoCommit => 0 }) or

--^------------^--useless use of quotes.  Note that this could be more 
than just two wasted keystrokes -- with the quotes, the variable will be 
stringified if it wasn't already a string.


>         err_trap("error connecting to DB");
>     return $dbh;
> }
 ...


I don't see where your program would have the described behavior, but 
the example is too complex to attempt to debug it with the supplied code 
and info.  I recommend you boil your example down to a complete 
self-contained piece of code including data which can be 
cut/paste/executed on anyone's computer (perhaps using DBD::CSV instead 
of mySQL) and shows the problem you are having.  Also use warnings; and 
use strict;.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



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

Date: Sun, 22 Feb 2004 11:07:15 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: parsing data file into mysql table - help
Message-Id: <c1a2ff$hma$1@news.simnet.is>

"smrtalec" <smrtalec_NO_SPAM@algxmail.com> wrote in message
news:3vUZb.21103$wD5.18798@nwrddc03.gnilink.net...
>
> #! /usr/bin/perl -w
there is a space after #!
I have no idea if it matters, but it scares me

>
    use strict;
also, instead of -w :
    use warnings;

always use strict, specially if you are having problems
use warnings too, at least when debugging

[snip]
>     my @$value = @_;
don't do this

[snipped positional INSERT with $dbh->quote()'s]
general form:
    my $sql = "INSERT INTO footable (col1,col2,col3...)
                      VALUES (?,?,?...)";
    my $sth_i = $dbh->prepare ($sql);
    my $res=$sth_i->execute($val1,$val2,$val3);
add error handling to taste

>
> sub verify_row {
>     my @$vrow = @_;
>     my $name_l =  $dbh->quote($vrow->[0]);
don't do this
    my @vrow = @_;
    my $name_l =  $dbh->quote($vrow[0]);
but look at placeholders here too

[snip more of the same]

>         while (<SDDB>) {
>             chomp $_;
>             my $row = [(split (/,/,$_))];
what is this fixation on arrayrefs?
then you do all these @$row constructs

gnari






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

Date: Sun, 22 Feb 2004 14:17:13 +0100
From: "chatiman" <chatiman@free.fr>
Subject: Questions on PAR
Message-Id: <4038abdf$0$21686$636a15ce@news.free.fr>

Hello,

I'm interested in using PAR for my CGI scripts.
Here 's a few question about it :
- Does PAR compile perl source scripts into perl bytecode or does it just
ompress the source code ?
- How do you use Filters to archieve source code obfuscation ?
- How difficult is it to "decompile" code obfuscated with PAR ?

Thanks





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

Date: Sun, 22 Feb 2004 14:50:01 +0100
From: Calle Dybedahl <calle@cyberpomo.com>
Subject: Re: Questions on PAR
Message-Id: <86r7wncjg6.fsf@ulthar.bisexualmenace.org>

>>>>> "chatiman" == chatiman  <chatiman@free.fr> writes:

> Here 's a few question about it :

The answers to which you could easily have found out for yourself by
reading the PAR documentation.

> - Does PAR compile perl source scripts into perl bytecode or does it just
> ompress the source code ?

Compress

> - How do you use Filters to archieve source code obfuscation ?

This has nothing to do with PAR, and is in general not possible. In
order to run your script, Perl must be able to read it, which means
that a human can also get at it.

> - How difficult is it to "decompile" code obfuscated with PAR ?

Utterly trivial. The documentation (specifically, PAR::FAQ) tells you
how. PAR is not an obfuscation tool.
-- 
		    Calle Dybedahl <calle@lysator.liu.se>
              Please pay no attention to the panda in the fridge.


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

Date: 22 Feb 2004 00:46:06 -0800
From: anichin@vip.bg (Angel)
Subject: Re: Replacing a text in multiple files with regular expressions
Message-Id: <8732d910.0402220046.1145da6d@posting.google.com>

"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message news:<55nZb.11202$Cd6.785896@news20.bellglobal.com>...
> "Angel" <anichin@vip.bg> wrote in message
> news:8732d910.0402192303.1f215d45@posting.google.com...
> > "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
>  news:<l55Zb.27814$5W3.6744@nwrddc02.gnilink.net>...
> > > Angel wrote:
> > >
> > > Then why didn't you say so in the beginning?
> > > And btw., no it is not possible to recurse through a directory structure
> > > using REs. Those two have nothing to do with each other.
> >
> > I said that:
> >
> > "I would like to search and replace on many files located in
> > different subfolders of one main folder."
> >
> 
> No that was just what you said you were trying to accomplish. You said your
> problem was that:
> 
> > I know it should be possible using regular expressions but
> > all my attempts failed. Can anyone help me ?
> 
> The "it" in the above sentence refers back to your original problem, which
> was to wrap all the images in anchor tags.
> 
> No one's interested in trying to read your mind. Next time state your
> problem clearly.
> 
> Matt


When I read my posting now I agree it did not state the problem clearly.
Next time I will try to be more specific. Thanks.


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

Date: Sun, 22 Feb 2004 06:03:35 GMT
From: "Suresh Govindachar" <sgovindachar@yahoo.com>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <XCXZb.2867$_3.45014@typhoon.sonic.net>

#!/usr/bin/perl
use warnings;
use strict;

use CGI qw(:standard);

=begin comment

Thanks for all the private and public response.

The upshot is that "use CGI qw(:standard);" results
in the $/ variable having the wrong value for STDIN,
and chomp'ing the stuff read from STDIN cannot remove
a trailing "\r" in the stuff.

Using the command "binmode STDIN;" before reading
from STDIN did not help.

Using "use CGI qw(:standard -debug);" is not a solution
since the context calls for the shell code to use
a different input scheme from that used by the cgi code;
and -debug is for when the shell code takes its input
using the same scheme as the cgi (for example, with
commands such as param("keyword")).

I haven't yet figured out hot to use the suggestion:

     if ($ENV{GATEWAY_INTERFACE})
     {
       require CGI;
       import CGI qw(:standard);
     }

since the code has lines such as the following:

    print header; # executed when param()

which causes the compiler to complain.

Anyway, for those who are interested in some more insight,
consider running this code on Windows with and
without commenting out the "use CGI qw(:standard);" line.

=end comment

=cut

(0) and print header; #compiler will complain if without CGI

print "Enter a number: ";
my $the_number = <STDIN>;

$the_number =~ m/\d*(.*)/so;
my $tail = $1;

($/ eq "\n")   and print "\tchomp eats \\n\n";
($/ eq "\r")   and print "\tchomp eats \\r\n";
($/ eq "\r\n") and print "\tchomp eats \\r\\n\n";

($tail eq "\n")   and print "\ttail equals \\n\n";
($tail eq "\r")   and print "\ttail equals \\r\n";
($tail eq "\r\n") and print "\ttail equals \\r\\n\n";

print "\nchomp will FAIL and output will look garbled\n" unless ($tail eq
$/);

chomp $the_number;

print "\n\tResults of $the_number rolls of a fair die:\n\n";
print "The number $the_number was returned from get_input\n\n\n";





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

Date: Sun, 22 Feb 2004 13:01:32 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <c1a62k$1f3308$1@ID-184292.news.uni-berlin.de>

Suresh Govindachar wrote:
> I haven't yet figured out hot to use the suggestion:
> 
>      if ($ENV{GATEWAY_INTERFACE})
>      {
>        require CGI;
>        import CGI qw(:standard);
>      }
> 
> since the code has lines such as the following:
> 
>     print header; # executed when param()
> 
> which causes the compiler to complain.

You'd better say:

     print header();

as long as CGI.pm is not always loaded in compile time.

Then you could for instance put that in the same block:

     if ($ENV{GATEWAY_INTERFACE})
     {
       require CGI;
       import CGI qw(:standard);
       print header();
     }

or in some other block that is only executed when the script is 
invoked from shell.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Sun, 22 Feb 2004 13:07:49 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Simple code runs on linux, but not on windows -- why?
Message-Id: <c1a6ed$1f0p52$1@ID-184292.news.uni-berlin.de>

Gunnar Hjalmarsson wrote:
> or in some other block that is only executed when the script is
> invoked from shell.

 ... that is *not* executed when ...

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 21 Feb 2004 22:42:04 -0800
From: adam@macrotex.net (A. Lewenberg)
Subject: Re: The times() function and child cpu time misbehavior
Message-Id: <6bd7331b.0402212242.118dad30@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c18jb8$d1o$2@mamenchi.zrz.TU-Berlin.DE>...
> A. Lewenberg <adam@macrotex.net> wrote in comp.lang.perl.misc:
> > The following code forks creating a child process that does some
> > CPU-intensive task. The parent process loops every 1 second and
> > displays the results of a call to the times() function. What is
> > puzzling is that the last 2 elements of the times() function call
> > never get larger than zero even though they are supposed
> > to reflect cpu time usage of all child processes. 
> > 
> > Is the times() function broken on this platform or am I
> > misunderstanding its use?
> 
> I believe the latter.  The times() function includes only the cpu times
> of finished children you have wait()'ed for.  I seem to understand you
> want to watch the kid's cpu time grow.  You can't do that from the
> parent, not through times().
> 
> If I'm misunderstanding your question, please ignore me.  This is just
> a quick reply, without looking at the code.
> 
> Anno

Yes, I believe you are correct. This is even hinted at in the man page
for times. Thanks again.


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

Date: Sun, 22 Feb 2004 13:13:00 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: Re: trapping file i/o error
Message-Id: <40383a53_2@rain.i-cable.com>

hmm... how do you force a variable into a certain context (could I also 
call it "type casting")?

for integer, $i+0 or (int)$i.
for string, $i+""? or is it (string)$i?
for array
for hash

> Yes.  but once you *do* know about it, it can be very convenient.

-- 
   .~.    Might, Courage, Vision. In Linux We Trust.
  / v \   http://www.linux-sxs.org
/( _ )\  Linux 2.4.22-xfs
   ^ ^    1:10pm up 2:19 1 user 1.41 1.33


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

Date: Sun, 22 Feb 2004 05:31:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: trapping file i/o error
Message-Id: <c19es9$lkc$1@wisteria.csv.warwick.ac.uk>


toylet <toylet_at_mail.hongkong.com> wrote:
> hmm... how do you force a variable into a certain context (could I also 
> call it "type casting")?

You almost never need to. About the time string/number matters is with
magic values like $!; other than that, scalar context can be forced with
scalar() or unary + and list context with parentheses ().

> for integer, $i+0 or (int)$i.

               yes      no, though int($i) will give you int rather than
                        float

> for string, $i+""? or is it (string)$i?

              $i.'' or "$i"    no

> for array
> for hash

eh what? Please explain what you expect, e.g., (hash)$i to achieve?

Ben

-- 
And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
                            * ben@morrow.me.uk *


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

Date: Sat, 21 Feb 2004 23:43:42 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: trapping file i/o error
Message-Id: <slrnc3ggce.8l2.tadmc@magna.augustmail.com>


[ comp.lang.perl removed, it is not a newsgroup ]


toylet <> wrote:

> hmm... how do you force a variable into a certain context 


By using it in the desired context.

   my($foo) = bar();  # bar() in list context

   my $foo  = bar();  # bar() in scalar context

Have you read the "Context" section in perldata.pod?

You can force scalar context with scalar().

You can often force list context with (parenthesis).


> (could I also 
> call it "type casting")?


No. Type casting has to do with the value of variables.

Context has to do with behavior, not with values.


> for integer, $i+0 or (int)$i.
> for string, $i+""? or is it (string)$i?

   "$i"

double quotes force stringification (but you don't need to
force stringification).


> for array

   my($foo) = @bar;  # @bar in list context

   my $foo  = @bar;  # @bar in scalar context


> for hash

   my($foo) = %bar;  # %bar in list context

   my $foo  = %bar;  # %bar in scalar context


( that last is useful to a perl programmer, but not useful
  to a Perl programmer.
)



[snip un-attributed TOFU. 
 Please learn to properly compose followups.

 Soon.
]

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


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

Date: Sun, 22 Feb 2004 15:24:49 +0800
From: toylet <toylet_at_mail.hongkong.com>
Subject: Re: trapping file i/o error
Message-Id: <40385938_1@rain.i-cable.com>

>> for array
>> for hash
> 
> eh what? Please explain what you expect, e.g., (hash)$i to achieve?

Just asking for a general method of forcing context.

-- 
   .~.    Might, Courage, Vision. In Linux We Trust.
  / v \   http://www.linux-sxs.org
/( _ )\  Linux 2.4.22-xfs
   ^ ^    3:24pm up 4:33 1 user 1.79 1.45


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

Date: 22 Feb 2004 01:38:50 -0800
From: dana_livni@hotmail.com (dana livni)
Subject: why do i get this error?
Message-Id: <1596f85c.0402220138.3e9e802d@posting.google.com>

i wort this script:

and when i try to run it. it start to work even inserts the rigth
information into the DataBase, but after 10-12 time the main loop
runs, i get this kind of error:


perl.exe application error
"the instruction at "0x7800ffe7" referenced memory at "0x04281228".
the memory could not be "read".

why? please help me.
---------------------------------------------------------------------------
#----------main program----------
use LWP::Simple;
use strict;
use Win32::ODBC;

open(INPUT, 'params.txt');
#my $company_symbol = <INPUT>;
#$company_symbol =~ m/Company Symbol\: (.+)/i;
#$company_symbol = $1;
my $dir = <INPUT>;
$dir =~ m/Dir to Save in\: (.+)/i;
$dir = $1;
my $dsn = <INPUT>;
$dsn =~ m/DataBase Nane\: (.+)/i;
$dsn = $1;
close INPUT;

#my $db = new Win32::ODBC($dsn);
my @company_symbols;
select_all();
for my $company_symbol(@company_symbols){
#-------get params--------

my $company_code = select_from($company_symbol);


#-------DownLoad the Major Holders URL--------
my $d_url1 = "http://finance.yahoo.com/q/mh?s=$company_symbol";
my $d_file1 = "$dir\\$company_symbol 1.txt";
my $dana = getstore($d_url1,$d_file1);
my $d_data1 = file_to_data($d_file1);

my $shareholder_name;
my $share_num;
my $share_percentage;
my $share_value;
my $time_reported;


#-------Parse and Insert the TOP INSIDER & RULE 144 HOLDERS
Data--------
$d_data1 =~ m/\<tr\>\<td\>\<small\>\<b\>TOP INSIDER \&amp\; RULE 144
HOLDERS\<\/b\>\<\/small\>\<\/td\>\<\/tr\>(.+?)\<\/table\>\<\/td\>\<\/tr\>\<\/table\>/ig;
my $temp_text = $1;
my @shareholder_detailes = ($temp_text =~ m/\<tr\>\<td
class\=\"yfnc\_tabledata1\"\>\<a
href\=\".+?"\>(.+?)\<\/a\>\<\/td\>\<td class\=\"yfnc\_tabledata1\"
align\=\"center\"\>(.+?)\<\/td\>\<td class\=\"yfnc\_tabledata1\"
align\=\"center\"\>(.+?)\<\/td\>\<\/tr\>/ig);
my $len = scalar(@shareholder_detailes);
for (my $j = 0;$j < $len;$j += 3)
{
	$shareholder_name = $shareholder_detailes[$j];
	$shareholder_name =~ s/\'/\"/ig;
	$share_num = $shareholder_detailes[$j+1] ;
	$time_reported = $shareholder_detailes[$j+2];
	insert_data($shareholder_name,'inside
holder',$company_code,$share_num,'  -  ','  -  ',$time_reported);
}


#-------Parse and Insert the TOP INSTITUTIONAL HOLDERS Data--------
$d_data1 =~ m/\<tr\>\<td\>\<small\>\<b\>TOP INSTITUTIONAL
HOLDERS\<\/b\>\<\/small\>\<\/td\>\<\/tr\>\<\/table\>(.+?)\<\/table\>\<\/td\>\<\/tr\>\<\/table\>/ig;
my $temp_text = $1;
my @shareholder_detailes = ($temp_text =~ m/\<tr\>\<td
class\=\"yfnc\_tabledata1\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\"
align\=\"right\"\>(.+?)\<\/td\>\<\/tr\>/ig);
my $len = scalar(@shareholder_detailes);
for (my $j = 0;$j < $len;$j += 5)
{
	$shareholder_name = $shareholder_detailes[$j];
	$shareholder_name =~ s/\'/\"/ig;
	$shareholder_name =~ s/\&amp\;/\&/ig;
	$share_num = $shareholder_detailes[$j+1] ;
	$share_percentage = $shareholder_detailes[$j+2] ;
	$share_value = $shareholder_detailes[$j+3] ;
	$time_reported = $shareholder_detailes[$j+4];
	insert_data($shareholder_name,'institution
holder',$company_code,$share_num,$share_percentage,$share_value,$time_reported);
}


#-------Parse and Insert the TOP MUTUAL FUND HOLDERS Data--------
$d_data1 =~ m/\<tr\>\<td\>\<small\>\<b\>TOP MUTUAL FUND
HOLDERS\<\/b\>\<\/small\>\<\/td\>\<\/tr\>\<\/table\>(.+?)\<\/table\>\<\/td\>\<\/tr\>\<\/table\>/ig;
my $temp_text = $1;
my @shareholder_detailes = ($temp_text =~ m/\<tr\>\<td
class\=\"yfnc\_tabledata1\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\" align\=\"right\"\>(.+?)\<\/td\>\<td
class\=\"yfnc\_tabledata1\"
align\=\"right\"\>(.+?)\<\/td\>\<\/tr\>/ig);
my $len = scalar(@shareholder_detailes);
for (my $j = 0;$j < $len;$j += 5)
{
	$shareholder_name = $shareholder_detailes[$j];
	$shareholder_name =~ s/\'/\"/ig;
	$shareholder_name =~ s/\&amp\;/\&/ig;
	$share_num = $shareholder_detailes[$j+1] ;
	$share_percentage = $shareholder_detailes[$j+2] ;
	$share_value = $shareholder_detailes[$j+3] ;
	$time_reported = $shareholder_detailes[$j+4];
	insert_data($shareholder_name,'mutual fond
holder',$company_code,$share_num,$share_percentage,$share_value,$time_reported);
}
print "finished handeling company - $company_symbol\n";
}
#$db->Close();

#----------subrutines----------	


#----------creating a variables with the file content----------
sub file_to_data
{
	my $file = shift @_;
	open(INPUT,$file);
	my @lines = <INPUT>;
	chomp(@lines);
	close INPUT;
	my $data = join('',@lines);
	return $data;
}


#----------insert data into tabe----------
sub insert_data 
{
	my $sql = "INSERT INTO
company_shareholders(holder_name,holder_type,company_code,share_num,share_percentage,share_value,time_reported)
VALUES('$_[0]','$_[1]','$_[2]','$_[3]','$_[4]','$_[5]','$_[6]')";
	my $db = new Win32::ODBC($dsn);
	$db->Sql($sql);
	$db->Close();
}


#----------select data from tabe----------
sub select_from
{
	my $sql = "SELECT company_code FROM symbols WHERE (company_symbol =
'$_[0]')";
	my $db = new Win32::ODBC($dsn);
	$db->Sql($sql);
	$db->FetchRow();
	my $company_code = $db->Data("company_code");
	$db->Close();
	return $company_code;
}


#----------select all company symbols from tabe----------
sub select_all
{
	my $sql = "SELECT company_symbol FROM symbols WHERE (company_symbol
like 'A%')";
	my $db = new Win32::ODBC($dsn);
	$db->Sql($sql);
	my $i = 0;
	while($db->FetchRow())
	{
	$company_symbols[$i] = $db->Data("company_symbol");
	$i++;
	}
	$db->Close();
}
---------------------------------------------------------------------------


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

Date: Sun, 22 Feb 2004 11:20:46 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: why do i get this error?
Message-Id: <c1a38t$ho6$1@news.simnet.is>

"dana livni" <dana_livni@hotmail.com> wrote in message
news:1596f85c.0402220138.3e9e802d@posting.google.com...
> i wort this script:
>
> and when i try to run it. it start to work even inserts the rigth
> information into the DataBase, but after 10-12 time the main loop
> runs, i get this kind of error:
>
>
> perl.exe application error
> "the instruction at "0x7800ffe7" referenced memory at "0x04281228".
> the memory could not be "read".
>
> why? please help me.
> --------------------------------------------------------------------------
-
> #----------main program----------
[snipped most of way too complex program to ask to be debugged here,
specially considering it reads unknown input data from file]

> open(INPUT, 'params.txt');

what happens if open fails?

> $dir =~ m/Dir to Save in\: (.+)/i;
> $dir = $1;

what does $1 contain if the match failed?

> my $dsn = <INPUT>;
> $dsn =~ m/DataBase Nane\: (.+)/i;
> $dsn = $1;

ditto

[gave up, snipped rest]

what you need to do is some basic debugging

does the problem still happen if you replace all the ODBC
stuff with dummy fuctions ?

does the problem still happen if you replace the LWP
stuff with simple preset data?

in fact try to simplify the program, by taking out all the parts not
needed to exhibit the problem. then replace all the file reads with
fixed variable assignements, make sure it compiles and show us.
(if you have not ready solved it)

gnari






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

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


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