[22692] in Perl-Users-Digest
Perl-Users Digest, Issue: 4913 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 30 03:07:40 2003
Date: Wed, 30 Apr 2003 00:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 30 Apr 2003 Volume: 10 Number: 4913
Today's topics:
another beginner question (Herb Burnswell)
Re: another beginner question <mbudash@sonic.net>
Re: another beginner question <mgjv@tradingpost.com.au>
Re: Comparing strings with small differences <mlm@nospam.com>
complex text/file search. help please!!! (supportgeek)
Re: complex text/file search. help please!!! <mbudash@sonic.net>
Re: errors passing values to sub from other sub with "u <goldbb2@earthlink.net>
Re: errors passing values to sub from other sub with "u (Tad McClellan)
Is it possible to pass @somethig and $something_else to <anthony@movielink.net.au>
Re: Is it possible to pass @somethig and $something_els <mbudash@sonic.net>
Re: Is it possible to pass @somethig and $something_els <budman85@adelphia.net>
Re: Is it possible to pass @somethig and $something_els <josef.moellers@fujitsu-siemens.com>
Newbie Problem: Cannot see result of .pl <dnegorsk@tampabay.rr.com>
Re: Newbie Problem: Cannot see result of .pl <johngros@bigpond.net.au>
Re: NEWBIE: using zip::archive to extract files that on <kalinabears@hdc.com.au>
Perl - DBI - How to store connection info in a separate (deepak p)
Re: Perl - DBI - How to store connection info in a sepa <mbudash@sonic.net>
Race problem in 5.6.1 - Not Von Neumann anymore? (John Long)
Re: Race problem in 5.6.1 - Not Von Neumann anymore? <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 29 Apr 2003 21:28:37 -0700
From: patyoung13@hotmail.com (Herb Burnswell)
Subject: another beginner question
Message-Id: <3b38898e.0304292028.362013e8@posting.google.com>
Hi,
Sorry if this is a basic question but I can't seem to find the correct
syntax. I would like to do something similar to:
@names = qw(name1 name2 name3 name4 name5 name6 name7);
for ( @names[0-6] )
{
do something.....
}
Can anyone point me in the correct direction here? perldoc? Is there
a better way to go about doing this? Any assistance is greatly
appreciated.
TIA,
Herb
------------------------------
Date: Wed, 30 Apr 2003 04:36:58 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: another beginner question
Message-Id: <mbudash-65127B.21365829042003@typhoon.sonic.net>
In article <3b38898e.0304292028.362013e8@posting.google.com>,
patyoung13@hotmail.com (Herb Burnswell) wrote:
> Hi,
>
> Sorry if this is a basic question but I can't seem to find the correct
> syntax. I would like to do something similar to:
>
>
>
> @names = qw(name1 name2 name3 name4 name5 name6 name7);
>
> for ( @names[0-6] )
> {
>
> do something.....
>
> }
>
>
> Can anyone point me in the correct direction here? perldoc? Is there
> a better way to go about doing this? Any assistance is greatly
> appreciated.
>
> TIA,
>
> Herb
not really sure what it is you're trying to do, but it looks like this
is what you want:
foreach (@names) {
# each name will be in $_
}
-or-
foreach my $name (@names) {
# each name will be in $name
}
hth-
--
Michael Budash
------------------------------
Date: Wed, 30 Apr 2003 06:28:50 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: another beginner question
Message-Id: <slrnbaur92.3gj.mgjv@verbruggen.comdyn.com.au>
On 29 Apr 2003 21:28:37 -0700,
Herb Burnswell <patyoung13@hotmail.com> wrote:
> Hi,
>
> Sorry if this is a basic question but I can't seem to find the correct
> syntax. I would like to do something similar to:
>
>
>
> @names = qw(name1 name2 name3 name4 name5 name6 name7);
>
> for ( @names[0-6] )
> {
>
> do something.....
>
> }
foreach my $name (@names)
{
# do something with $name, which BTW is an alias for each of the
# elements in @names in turn. Modifying $name modifies the
# original element.
}
or, if you don't like to use an explicit variable name
foreach (@names)
{
# do something with $_. The same aliasing applies.
}
(for and foreach are the same, but for this sort of construct I tend
to prefer foreach)
> Can anyone point me in the correct direction here? perldoc? Is there
> a better way to go about doing this? Any assistance is greatly
> appreciated.
The documentation you might be interested in is the perlsyn manual
page, available with 'perldoc perlsyn'. It also explains the aliasing
behaviour for foreach loops.
Martien
--
|
Martien Verbruggen | I used to have a Heisenbergmobile. Every time
Trading Post Australia | I looked at the speedometer, I got lost.
|
------------------------------
Date: Tue, 29 Apr 2003 21:03:36 -0500
From: mlm <mlm@nospam.com>
Subject: Re: Comparing strings with small differences
Message-Id: <yVCdnbUOMcxlszKjXTWcog@giganews.com>
Hey that is a great help Winfried. I am working out how it works now
...
Thanks
mark
Winfried Koenig <w.koenig@acm.org> wrote in news:3EAD9204.9010508
@acm.org:
> #!/usr/local/bin/perl
>
> use strict;
> use warnings;
>
> my @a = (
> "Polka dot (18), sheet 07.",
> "Polka dot (19), sheet 07.",
> "Polka dot (20), sheet 07.",
> );
>
> foreach my $i (1 .. $#a) {
> my $diff = $a[$i -1 ] ^ $a[$i];
> if ($diff =~ m/[^\000]+/) {
> printf "%d,%d\n", $-[0], $+[0] - $-[0];
> }
> }
>
> __END__
>
------------------------------
Date: 29 Apr 2003 20:30:03 -0700
From: molivier@caregroup.harvard.edu (supportgeek)
Subject: complex text/file search. help please!!!
Message-Id: <da063e5d.0304291930.704cf3c4@posting.google.com>
Ok. Here's the problem I've been having, "forever!". Thanks so much to
anyone who can just point me in the right direction "again!" on this
one.
I have a large file full of reports. Each report is separated by a
form feed \f character. Here is what I need to do:
I need to search the file for the the lines that match /^7002/ and if
there is a match I need to print those lines and their matching
account number. If there is not match of /^7002/, I do not want to
pull any data from that record. Below is an example of the file, and
then an example of the data I need to pull.
#EXAMPLE OF THE FILE**************
#record 1 #account number
145 Main St 001-34562032-100 831
Pete's Auto Parts
John Doe 345 Generic Lane (617)564.34235
1001 GAS TANK
1005 GAS CAP
7002 SPARK PLUG 45345
7002 SPARK PLUG 234234
9199 PAINT
001 Beach Insurance
/f #record 2
145 Main St 001-3754332-100 831
Pete's Auto Parts
Britney Spears 35 Hotbody Lane (617)444.3415
1002 BUMPER
9199 PAINT
001 Sandbar Insurance
014 Rockafeller Ins.
/f #record 3
145 Main St 001-6734232-100 831
Pete's Auto Parts
Filipe Rogers 31 Rockstar Lane (617)134.34435
1001 GAS Valve
7002 SPARK PLUG 4342534523
9189 DEISEL FUEL
001 Beach Insurance
/f
#Example of the data I need to pull
#from record 1
145 Main St 001-34562032-100 831
7002 SPARK PLUG 45345
7002 SPARK PLUG 234234
#from record 3
145 Main St 001-6734232-100 831
7002 SPARK PLUG 4342534523
As you can see I do not want to bother with the second record because
it has no line line that starts with ^7002. I Would prefer to pull
just the account number, but the whole line will do.
Thank You in advance for any help on this. If you need any more info
from me please let me know.
------------------------------
Date: Wed, 30 Apr 2003 04:34:11 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: complex text/file search. help please!!!
Message-Id: <mbudash-60E92B.21341029042003@typhoon.sonic.net>
In article <da063e5d.0304291930.704cf3c4@posting.google.com>,
molivier@caregroup.harvard.edu (supportgeek) wrote:
> Ok. Here's the problem I've been having, "forever!". Thanks so much to
> anyone who can just point me in the right direction "again!" on this
> one.
>
> I have a large file full of reports. Each report is separated by a
> form feed \f character. Here is what I need to do:
>
> I need to search the file for the the lines that match /^7002/ and if
> there is a match I need to print those lines and their matching
> account number. If there is not match of /^7002/, I do not want to
> pull any data from that record. Below is an example of the file, and
> then an example of the data I need to pull.
>
> #EXAMPLE OF THE FILE**************
> #record 1 #account number
>
> 145 Main St 001-34562032-100 831
> Pete's Auto Parts
>
> John Doe 345 Generic Lane (617)564.34235
>
> 1001 GAS TANK
> 1005 GAS CAP
> 7002 SPARK PLUG 45345
> 7002 SPARK PLUG 234234
> 9199 PAINT
>
> 001 Beach Insurance
> /f #record 2
> 145 Main St 001-3754332-100 831
> Pete's Auto Parts
>
> Britney Spears 35 Hotbody Lane (617)444.3415
>
> 1002 BUMPER
> 9199 PAINT
>
> 001 Sandbar Insurance
> 014 Rockafeller Ins.
> /f #record 3
> 145 Main St 001-6734232-100 831
> Pete's Auto Parts
>
> Filipe Rogers 31 Rockstar Lane (617)134.34435
>
> 1001 GAS Valve
> 7002 SPARK PLUG 4342534523
> 9189 DEISEL FUEL
>
> 001 Beach Insurance
> /f
>
>
> #Example of the data I need to pull
>
> #from record 1
> 145 Main St 001-34562032-100 831
> 7002 SPARK PLUG 45345
> 7002 SPARK PLUG 234234
>
> #from record 3
> 145 Main St 001-6734232-100 831
> 7002 SPARK PLUG 4342534523
>
> As you can see I do not want to bother with the second record because
> it has no line line that starts with ^7002. I Would prefer to pull
> just the account number, but the whole line will do.
>
> Thank You in advance for any help on this. If you need any more info
> from me please let me know.
this should get you started:
open (D, "data") or die ("Can't open data: $!");
local $/ = "\f";
while (<D>) {
if (/^7002/m) {
my @lines = split /\n/;
print shift @lines, "\n";
foreach (@lines) {
print "$_\n" if /^7002/;
}
}
}
hth-
--
Michael Budash
------------------------------
Date: Tue, 29 Apr 2003 22:08:06 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: errors passing values to sub from other sub with "use strict"
Message-Id: <3EAF3006.16E4B273@earthlink.net>
Tony wrote:
[snip]
> @list = ("/this/path/file_1.txt 1", "this/path/file_2.txt 3");
>
> process_list(@list)
>
^
";" missing.
> sub process_list
> {
> foreach $item(@LIST);
This line is both a syntax error, and a strict vars violation.
--
$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: Tue, 29 Apr 2003 21:17:47 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: errors passing values to sub from other sub with "use strict"
Message-Id: <slrnbaucib.3el.tadmc@magna.augustmail.com>
Tony <anthony@movielink.net.au> wrote:
> However switching on "use strict" still splutters....
>
> A little more fiddling turned out that I was not defining
> all $var's as local (my $something)
Did the fiddling include:
perldoc strict
?
The docs for the software you are using are always more reliable,
and usually faster, than "fiddling".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 30 Apr 2003 15:41:34 +1000
From: "Tony" <anthony@movielink.net.au>
Subject: Is it possible to pass @somethig and $something_else to sub
Message-Id: <pan.2003.04.30.05.41.33.793363@movielink.net.au>
Hi guys,
Just a short Q,
I have:
my @list = ("something","something_else","something_more",...could go on")
my $string = $string_from_other_part_of_program;
I wish to send the $string together with @list to a sub process
like this:
process($string,@list);
sub process {
my $local_string = $_[0];
my @local_list = @_;
...
Process $local_list in various ways depending on value of $local_string
}
This does not seem to do what I want, the docs say something
about everything being "flattened" when passing to a sub.
It looks like it is not possible or legal to do this.
Is it possible some way or do I need to store the $string in
a global variable so the sub can pick it up?
Tony
--
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net
------------------------------
Date: Wed, 30 Apr 2003 05:58:29 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Is it possible to pass @somethig and $something_else to sub
Message-Id: <mbudash-3E1F2B.22582929042003@typhoon.sonic.net>
In article <pan.2003.04.30.05.41.33.793363@movielink.net.au>,
"Tony" <anthony@movielink.net.au> wrote:
> Hi guys,
>
> Just a short Q,
>
> I have:
>
> my @list = ("something","something_else","something_more",...could go on")
> my $string = $string_from_other_part_of_program;
>
> I wish to send the $string together with @list to a sub process
> like this:
>
> process($string,@list);
>
> sub process {
>
> my $local_string = $_[0];
> my @local_list = @_;
> ...
> Process $local_list in various ways depending on value of $local_string
> }
>
> This does not seem to do what I want, the docs say something
> about everything being "flattened" when passing to a sub.
>
>
> It looks like it is not possible or legal to do this.
>
> Is it possible some way or do I need to store the $string in
> a global variable so the sub can pick it up?
>
> Tony
two ways would work for you:
1)
process($string, @list);
sub process {
my $local_string = shift;
my @local_list = @_;
...
Process @local_list array depending on val of $local_string
}
2)
process($string, \@list);
sub process {
my ($local_string, $local_list_ref) = @_;
...
Process @$local_list_ref array depending on val of $local_string
}
hth-
--
Michael Budash
------------------------------
Date: Wed, 30 Apr 2003 02:04:04 -0400
From: "Rich" <budman85@adelphia.net>
To: "Tony" <anthony@movielink.net.au>
Subject: Re: Is it possible to pass @somethig and $something_else to sub
Message-Id: <pan.2003.04.30.06.03.50.290055@adelphia.net>
Hi,
Well... there are a few ways...
&process( $string, \@list);
sub process {
my ( $str, $a_ref ) = @_;
my @Array = @{$a_ref};
}
}
------------------------------
&process( $string, @list );
sub process {
my ( $string, @Array ) = shift, @_;
}
}
If the list is small, and will always be small, then the 2nd method is
fine. If the @list may grow to be very large, the first method is much
better, also if you want to pass a hash, use the first method.
Hope this helps,
Rich
On Wed, 30 Apr 2003 15:41:34 +1000, Tony wrote:
> Hi guys,
>
> Just a short Q,
>
> I have:
>
> my @list = ("something","something_else","something_more",
> ...could go on")
> my $string = $string_from_other_part_of_program;
>
> I wish to send the $string together with @list to a sub process like
> this:
>
> process($string,@list);
>
> sub process {
>
> my $local_string = $_[0];
> my @local_list = @_;
> ...
> Process $local_list in various ways depending on value of
>$local_string
> }
> }
> This does not seem to do what I want, the docs say something about
> everything being "flattened" when passing to a sub.
>
>
> It looks like it is not possible or legal to do this.
>
> Is it possible some way or do I need to store the $string in a global
> variable so the sub can pick it up?
>
> Tony
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
------------------------------
Date: Wed, 30 Apr 2003 08:49:28 +0200
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Is it possible to pass @somethig and $something_else to sub
Message-Id: <3EAF71F8.382272CD@fujitsu-siemens.com>
Tony wrote:
> =
> Hi guys,
> =
> Just a short Q,
> =
> I have:
> =
> my @list =3D ("something","something_else","something_more",...could go=
on")
> my $string =3D $string_from_other_part_of_program;
> =
> I wish to send the $string together with @list to a sub process
> like this:
> =
> process($string,@list);
> =
> sub process {
> =
> my $local_string =3D $_[0];
> my @local_list =3D @_;
> ...
> Process $local_list in various ways depending on value of $local_stri=
ng
> }
> =
> This does not seem to do what I want, the docs say something
What is it it "does not seem to do what I want"?
> It looks like it is not possible or legal to do this.
It's perfectly legal, but ... is it what you want? (see above).
> Is it possible some way or do I need to store the $string in
> a global variable so the sub can pick it up?
I guess (see above) that your problem is that you are not removing
$local_string from the argument list, so @local_list will contain
$local_string as its first element.
Try putting
print join(",", @local_list), "\n";
just after the "my @local_list =3D @_;" to see this.
Then replace "my $local_string =3D $_[0];" by
my $local_string =3D shift;
HTH,
Josef
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 30 Apr 2003 03:33:33 GMT
From: "CHM" <dnegorsk@tampabay.rr.com>
Subject: Newbie Problem: Cannot see result of .pl
Message-Id: <huHra.41024$sn6.586477@twister.tampabay.rr.com>
I am new to Perl and use of IIS 5.1 (XP pRO). I am having loads of problems,
mainly seeing the .pl. I
am studying but this is a crucial roadblock to me. I have to know how to see
the .pl? The following is
an html page and the .pl to go with it. I am currently using IIS 5.1 as my
server. As close as I can
get is tobe on my HTML page, click the "Add Record", and see a box "file
downloading", with a progress
bar that is full. It disappears quickly and I am left with the HTML screen.
What the hell do I need to
do?
(Sample of HTML)
<html>
<head>
<title>Practice Form 1</title>
</head>
<body>
<font face="arial" size="2" color="#dd8040">
<h2>Add a Phone Number</h2>
<form name="phoneform" method="post" action = "C:/Inetpub/Scripts/test2.pl">
<table width="500">
<tr> <th width="200"></th><th width="300"></th></tr>
<tr><td>Forname</td><td><input type="text" name="forname"></td></tr>
<tr><td>Surname</td><td><input type="text" name="surname"></td></tr>
<tr><td>Department</td><td><input type="text" name="department"></td></tr>
<tr><td>Phone No:</td><td><input type="text" name="phone no:"</td></tr>
<tr><td>Comments</td><td><textarea name="comments" cols="50"
rows="4"></textarea></td></tr>
<tr><td><input type="submit" name="submit" value="Add Record"></td>
<td><input type="reset" name="reset" value="Reset"</td></tr>
</table>
</form>
</font>
</body>
</html>
(Sample of Perl)
#! c:/Perl/bin
print "Content-type: text/html\n\n";
read(STDIN,$tempbuffer,$ENV{'CONTENT-LENGTH'});
@pairs=split(/&/,$tempbuffer);
foreach $item(@pairs)
{
($key,$content)=split(/=/,$item,2);
$content=~tr/+/ /;
$content=~s/%(..)/pack("c",hex($1)) /g;
$fields{$key}=$content;
print "<font face=verdana size=2 color=darkred>$key</font>";
print "Contains <font face=verdana size=2
color=darkblue>$content</font><br>";
}
------------------------------
Date: Wed, 30 Apr 2003 06:21:11 GMT
From: "John Gros" <johngros@bigpond.net.au>
Subject: Re: Newbie Problem: Cannot see result of .pl
Message-Id: <rXJra.7476$lD4.79291@news-server.bigpond.net.au>
This is your IIS settings not perl, you have to configure the IIS server to
execute cgi in your cgi-bin, and have your perl script in the cgi-bin. You
may have to reconfigure your HTML page to point to the new location of your
perl script.
"CHM" <dnegorsk@tampabay.rr.com> wrote in message
news:huHra.41024$sn6.586477@twister.tampabay.rr.com...
> I am new to Perl and use of IIS 5.1 (XP pRO). I am having loads of
problems,
> mainly seeing the .pl. I
>
> am studying but this is a crucial roadblock to me. I have to know how to
see
> the .pl? The following is
>
> an html page and the .pl to go with it. I am currently using IIS 5.1 as my
> server. As close as I can
>
> get is tobe on my HTML page, click the "Add Record", and see a box "file
> downloading", with a progress
>
> bar that is full. It disappears quickly and I am left with the HTML
screen.
> What the hell do I need to
>
> do?
>
> (Sample of HTML)
>
> <html>
> <head>
> <title>Practice Form 1</title>
> </head>
> <body>
>
> <font face="arial" size="2" color="#dd8040">
> <h2>Add a Phone Number</h2>
>
> <form name="phoneform" method="post" action =
"C:/Inetpub/Scripts/test2.pl">
>
> <table width="500">
> <tr> <th width="200"></th><th width="300"></th></tr>
> <tr><td>Forname</td><td><input type="text" name="forname"></td></tr>
>
> <tr><td>Surname</td><td><input type="text" name="surname"></td></tr>
> <tr><td>Department</td><td><input type="text" name="department"></td></tr>
> <tr><td>Phone No:</td><td><input type="text" name="phone no:"</td></tr>
> <tr><td>Comments</td><td><textarea name="comments" cols="50"
> rows="4"></textarea></td></tr>
> <tr><td><input type="submit" name="submit" value="Add Record"></td>
> <td><input type="reset" name="reset" value="Reset"</td></tr>
>
> </table>
> </form>
> </font>
> </body>
> </html>
>
> (Sample of Perl)
>
> #! c:/Perl/bin
>
> print "Content-type: text/html\n\n";
>
> read(STDIN,$tempbuffer,$ENV{'CONTENT-LENGTH'});
>
> @pairs=split(/&/,$tempbuffer);
>
> foreach $item(@pairs)
>
> {
>
> ($key,$content)=split(/=/,$item,2);
>
> $content=~tr/+/ /;
>
> $content=~s/%(..)/pack("c",hex($1)) /g;
>
> $fields{$key}=$content;
>
> print "<font face=verdana size=2 color=darkred>$key</font>";
>
> print "Contains <font face=verdana size=2
> color=darkblue>$content</font><br>";
>
>
>
>
> }
>
>
>
>
------------------------------
Date: Wed, 30 Apr 2003 11:58:46 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: NEWBIE: using zip::archive to extract files that only end in 1p.eps
Message-Id: <3eaf2edd$0$23931@echo-01.iinet.net.au>
"jdlail" <jdlail@hotmail.com> wrote in message
news:e32bb269.0304291040.463e6f9d@posting.google.com...
> I need a little help in figuring out how to extract from a zip file
> only those files that end in 1p.eps using zip::archive.
>
> Can anybody give me some example code for that?
>
> -- jack lail
This works fine for me:
use Archive::Zip qw(AZ_OK);
use strict;
use warnings;
# Nominate the zip file.
my $zipfile = 'D:\perlmods\AdminMisc_source.zip';
my $zip = Archive::Zip->new();
# Read it in and check that it worked ok.
die 'read error' unless $zip->read( $zipfile ) == AZ_OK;
# Create an array of all of the files in the zip.
my @files = $zip->memberNames();
# Extract the files we want.
for(@files) {
if ($_ =~ /1p\.eps$/i) { # Case insensitive (?)
$zip->extractMemberWithoutPaths($_);
# or, to extract with paths:
# $zip->extractMember($_);
}
}
Cheers,
Rob
------------------------------
Date: 29 Apr 2003 21:02:21 -0700
From: deepak10000@hotmail.com (deepak p)
Subject: Perl - DBI - How to store connection info in a separate file
Message-Id: <9e77c6b2.0304292002.68bc2839@posting.google.com>
Hello,
I was wondering if anyone knows the syntax to include DBI connection
info in a separate file and make a call to it from a perl dbi script.
In the past, I have connection info hard coded in my dbi scripts and
they ran file. However, its preferable that this info. is kept in an
include file..that gets called instead of having this static info -
hard coded in my dbi scripts.
I have tried to commenting out the database connection info from my
dbi scripts and copied the lines over to a file called
"connection.info" also residing in the same directory and then tried
inserting stmts like
include "connection.info"
and even use connection.info, require connection.info..though these
are not right...in my dbi scripts..but the scripts fail. They of
course run fine, if all database connection info is in the body of the
script itself. Can anyone show me how I can do this? Thanks in
advance. My env is perl 5.61 runnding on HPUX - if that matters. I
have pasted a small section of my dbi code below..
#!/usr/local/bin/perl -w
use DBI;
use strict;
#=======================================================================
#Set all the variables needed for db Connection
#=======================================================================
my $sid = "xxxx";
my $host = "yyyy";
my $usr = "readonly";
my $pwd = "readonly";
my %rowH;
my $row;
my $dbh = DBI->connect("dbi:Oracle:host=$host;sid=$sid", $usr,
$pwd,{RaiseError => 1, AutoCommit => 0})
or die (__LINE__."ERROR: ". $DBI::errstr);
print "Connection established: $dbh \n";
###########
my $sth = $db->prepare("SELECT xxxxxxxxxxxxxxx);
$sth->execute;
$dbh->disconnect();
------------------------------
Date: Wed, 30 Apr 2003 04:38:57 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Perl - DBI - How to store connection info in a separate file
Message-Id: <mbudash-73F198.21385729042003@typhoon.sonic.net>
In article <9e77c6b2.0304292002.68bc2839@posting.google.com>,
deepak10000@hotmail.com (deepak p) wrote:
> Hello,
>
> I was wondering if anyone knows the syntax to include DBI connection
> info in a separate file and make a call to it from a perl dbi script.
>
> In the past, I have connection info hard coded in my dbi scripts and
> they ran file. However, its preferable that this info. is kept in an
> include file..that gets called instead of having this static info -
> hard coded in my dbi scripts.
>
> I have tried to commenting out the database connection info from my
> dbi scripts and copied the lines over to a file called
> "connection.info" also residing in the same directory and then tried
> inserting stmts like
>
> include "connection.info"
>
> and even use connection.info, require connection.info..though these
> are not right...in my dbi scripts..but the scripts fail. They of
> course run fine, if all database connection info is in the body of the
> script itself. Can anyone show me how I can do this? Thanks in
> advance. My env is perl 5.61 runnding on HPUX - if that matters. I
> have pasted a small section of my dbi code below..
>
> #!/usr/local/bin/perl -w
> use DBI;
> use strict;
> #=======================================================================
> #Set all the variables needed for db Connection
> #=======================================================================
> my $sid = "xxxx";
> my $host = "yyyy";
> my $usr = "readonly";
> my $pwd = "readonly";
> my %rowH;
> my $row;
> my $dbh = DBI->connect("dbi:Oracle:host=$host;sid=$sid", $usr,
> $pwd,{RaiseError => 1, AutoCommit => 0})
> or die (__LINE__."ERROR: ". $DBI::errstr);
>
> print "Connection established: $dbh \n";
>
> ###########
>
> my $sth = $db->prepare("SELECT xxxxxxxxxxxxxxx);
>
> $sth->execute;
>
> $dbh->disconnect();
what do you mean by 'fail'? what error message(s) do you see? show us
the code that 'fails'.
btw, 'require' is probably what you want, but it's certainly not the
only way...
hth-
--
Michael Budash
------------------------------
Date: 29 Apr 2003 19:30:25 -0700
From: goog1@pruam.com (John Long)
Subject: Race problem in 5.6.1 - Not Von Neumann anymore?
Message-Id: <24ea2723.0304291830.5788a66f@posting.google.com>
I have a bit of a problem here, Threads should be of no
concern because there should be just one but it acts like
there is another that runs off to do the rest of the code and
write the file while one thread is waiting on the os for the
-e.
I just upgraded to 5.6.1 from 5.005.03 where there was no
problem. This is cut down from several hundred lines.
If I have a form and post a single field (name) to this cgi,
it should wait at the -e and if the file does not exist then
go on and create it. What is happening 30-80% of the time is
that it says file exists and exits, I look and the file does
now exist where it did not before.
parse data...
$FORM{'name'} =~ /^([\w]*)$/; # untaint data
$name = $1;
if (-e "$dir/$name.dat") {
&message("That file \"$name\" already exists");
exit;
}
open FILE, ">$dir/$name.dat" || die "Unable to save file: $!" ;
print FILE "some data";
close FILE;
So I do it in mysql and with a clean table aa is ok but aaa fails
with an exists even tho aaa was not there and it still writes
the data.
use DBI;
$dbh = DBI->connect("dbi:mysql:db", "li", "pw") or
&err("Can't connect to db: ",$dbh->errstr);
$sth = $dbh->prepare("select * from tbl where name = ?") or
&err("Can't select from table: ",$dbh->errmsg);
$sth->execute($name);
@out = $sth->fetchrow;
if ($#out >= 0) {
&err("The name $name already exists. \n @out");
}
$sth = $dbh->prepare("insert into tbl values(?, ?)") or
&err("Can't add data to user table: ",$dbh->errmsg);
$sth->execute($name, $tdate);
sub err {
my $msg = @_;
print "<h2>Error</h2>\n";
print $msg;
exit;
}
=====================================================================
What gives here? this is 5.6.1 from ports, freebsd 4.8 stable
/home/john#perl -V
Summary of my perl5 (revision 5.0 version 6 subversion 1)
configuration:
Platform:
osname=freebsd, osvers=4.7-release, archname=i386-freebsd
uname='freebsd sys.dom.com 4.7-release freebsd 4.7-release #4: tue
oct 15 16:47:06 pdt 2002 '
config_args='-sde -Dprefix=/usr/local
-Darchlib=/usr/local/lib/perl5/5.6.1/mach
-Dprivlib=/usr/local/lib/perl5/5.6.1 -Dman3dir=/
usr/local/lib/perl5/5.6.1/man/man3
-Dsitearch=/usr/local/lib/perl5/site_perl/5.6.1/mach
-Dsitelib=/usr/local/lib/perl5/site_perl/5.6
.1 -Ui_malloc -Ui_iconv
-Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.6.1/BSDPAN" -Ui_gdbm
-Dusemymalloc=n'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
Compiler:
cc='cc', ccflags
='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.6.1/BSDPAN"
-fno-strict-aliasing -I/usr/local/include',
optimize='-O -pipe ',
cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.6.1/BSDPAN"
-fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='2.95.4 20020320 [FreeBSD]',
gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags ='-Wl,-E -L/usr/local/lib'
libpth=/usr/lib /usr/local/lib
libs=-lm -lc -lcrypt -lutil
perllibs=-lm -lc -lcrypt -lutil
libc=, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-DPIC -fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: USE_LARGE_FILES
Built under freebsd
Compiled at Dec 27 2002 17:06:15
@INC:
/usr/local/lib/perl5/site_perl/5.6.1/mach
/usr/local/lib/perl5/site_perl/5.6.1
/usr/local/lib/perl5/site_perl/5.005/i386-freebsd
/usr/local/lib/perl5/site_perl/5.005
/usr/local/lib/perl5/site_perl
/usr/local/lib/perl5/5.6.1/BSDPAN
/usr/local/lib/perl5/5.6.1/mach
/usr/local/lib/perl5/5.6.1
.
------------------------------
Date: Tue, 29 Apr 2003 22:54:31 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Race problem in 5.6.1 - Not Von Neumann anymore?
Message-Id: <3EAF3AE7.66FAE8D8@earthlink.net>
John Long wrote:
[snip]
> if (-e "$dir/$name.dat") {
> &message("That file \"$name\" already exists");
> exit;
> }
>
> open FILE, ">$dir/$name.dat" || die "Unable to save file: $!" ;
This might not be relevant to the particular problem you've got, but...
What happens if, *between* your doing "-e", and doing "open", the file
gets created by another process?
--
$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: 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 4913
***************************************