[23584] in Perl-Users-Digest
Perl-Users Digest, Issue: 5791 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 13 09:06:12 2003
Date: Thu, 13 Nov 2003 06:05:14 -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 Thu, 13 Nov 2003 Volume: 10 Number: 5791
Today's topics:
Re: "tree" view of directory <dominix"at"despammed.com>
#!perl instead of #!/usr/bin/perl on a Unix/Apache webs <tunmaster@hotmail.com>
Re: #!perl instead of #!/usr/bin/perl on a Unix/Apache <jwillmore@remove.adelphia.net>
Re: #!perl instead of #!/usr/bin/perl on a Unix/Apache <josef.moellers@fujitsu-siemens.com>
Re: #!perl instead of #!/usr/bin/perl on a Unix/Apache <tunmaster@hotmail.com>
Re: a Post-script to flocking question <tassilo.parseval@rwth-aachen.de>
Re: count of 1s in a binary number (Sara)
Re: count of 1s in a binary number <steffen.beyer@de.bosch.com>
Data Dumper guidance <kaspREMOVE_CAPS@epatra.com>
Re: Data Dumper guidance <ak+usenet@freeshell.org>
Re: Data Dumper guidance <kaspREMOVE_CAPS@epatra.com>
Re: DBD-Oracle-1.14 <r_reidy@comcast.net>
Re: fetchall_arrayref into bind_param_array (Oliver G)
Re: fetchall_arrayref into bind_param_array <jwillmore@remove.adelphia.net>
Re: fetchrow not proceeding beyond 9th record ctcgag@hotmail.com
File Append Issue <karigna_no@verizon.net>
Re: File Append Issue <kaspREMOVE_CAPS@epatra.com>
Re: how to erase \r or \015 in win32? (the zorg )
Re: how to erase \r or \015 in win32? <josef.moellers@fujitsu-siemens.com>
Re: Installation of a perl module <jim.mozley@exponential-e.com>
Re: Installation of a perl module (mistletoe)
Re: Installation of a perl module <jwillmore@remove.adelphia.net>
Re: Installation of a perl module <HelgiBriem_1@hotmail.com>
installing a perl module <kingsman22004@yahoo.com>
Re: installing a perl module <usenet@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 12 Nov 2003 21:34:51 -1000
From: "dominix" <dominix"at"despammed.com>
Subject: Re: "tree" view of directory
Message-Id: <3fb3341c$0$27602$626a54ce@news.free.fr>
Jeff Thies wrote:
> I'd like to have a tree like listing of a directories contents and
> it's subdirectories. I'd like to do that with the modules from the
> standard perl distribution.
>
this one should fit !
it's not from me but I've found it on an open source web site
#!/usr/bin/perl
#
# Yet another program to do a directory tree
#
# By Brian Blackmore (bnb@ukc.ac.uk)
# Modified by Thorsten Meinecke (kaefer@aglaia.in-berlin.de)
#
if ($ENV{'PWD'}) {
$pwd = $ENV{'PWD'};
} else { chop ($pwd = `sh -c "pwd"`);
}
if ($#ARGV+1) {
$dir = &resolve($ARGV[0],$pwd);
} else { $dir = &resolve(".",$pwd);
}
print;
s/./ /g;
&tree($dir, $_);
# This function resolves a pathname into its shortest version
# Removing any references to the directory . , any references
# to // , any references to directory/.. and any final /
sub resolve {
local($file,$direct) = @_;
$_ = $file.'/';
m#^/# || s#^#$direct/#;
while (s#/\.?/#/# || s#/[^/]+/\.\./#/# || s#/\.?$##) { }
$_ = '/' if ($_ eq "");
return $_;
}
# This function does all the work, it scans a directory and
# then prints out the files in each directory in a pretty format
# Note: It is recursive
sub tree {
local($dir,$level) = @_;
local(@files) = ();
local(%subdirs)= ();
if (!opendir(DIRECT,"$dir")) {
warn "Could not open directory $dir, bailing out\n";
return;
}
while ($name = readdir(DIRECT)) {
unless ($name =~ /^\.\.?$/) { # Skip . && ..
&resolve($name,$dir);
if (-d) {
if (-l) { # Do not follow symlinks
$name .= " -> " . readlink() . "\n";
} elsif (-r && -x) {
# We must be able to enter a directory in order to tree it
$subdirs{$name} = $_;
} else {
$name .= " (unreadable)\n";
}
push (@files, $name);
}
}
}
closedir(DIRECT);
@files = sort @files;
{
print ("\n"), last unless ($_ = shift @files);
print "---";
} continue {
print;
if ($newname = $subdirs{$_}) {
s/./ /g;
if (@files) {
&tree ($newname, "$level | $_");
} else {
&tree ($newname, "$level $_");
}
}
last unless ($_ = shift @files);
if (@files) {
print "$level |-";
} else {
print "$level \\-";
}
next;
} %subdirs = ();
}
------------------------------
Date: Thu, 13 Nov 2003 11:54:46 GMT
From: "joe" <tunmaster@hotmail.com>
Subject: #!perl instead of #!/usr/bin/perl on a Unix/Apache webserver
Message-Id: <aiKsb.109560$di.27225884@amsnews02.chello.com>
Hi there!
Can anyone help me out here. I run my CGI-scripts locally on a Windows
machine. In the shebang line I put #!c:\www\Perl.exe, but it's also possible
to use only #!perl. On my virtual webserver at my ISP's Unix machine I have
to use #!/usr/bin/perl.
The problem is that everytime I upload a script, I have to change the
shebang line from Windows-mode to Unix-mode.
Since the #!perl version sounds pretty universal, I was wondering whether it
is possible to make some sort of link: when 'perl' is requested, Apache
redirects to #!/usr/bin/perl. Or something else to accomplish the same
effect. My ISP doesn't know how to do this, without having to move the
Perl-module completely.
I'd be very gratefull if anyone could help me out!
Tia,
Joe
------------------------------
Date: Thu, 13 Nov 2003 12:07:52 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: #!perl instead of #!/usr/bin/perl on a Unix/Apache webserver
Message-Id: <20031113070408.77ec2de6.jwillmore@remove.adelphia.net>
On Thu, 13 Nov 2003 11:54:46 GMT
"joe" <tunmaster@hotmail.com> wrote:
> Hi there!
>
> Can anyone help me out here. I run my CGI-scripts locally on a
> Windows machine. In the shebang line I put #!c:\www\Perl.exe, but
> it's also possible to use only #!perl. On my virtual webserver at my
> ISP's Unix machine I have to use #!/usr/bin/perl.
>
> The problem is that everytime I upload a script, I have to change
> the shebang line from Windows-mode to Unix-mode.
>
> Since the #!perl version sounds pretty universal, I was wondering
> whether it is possible to make some sort of link: when 'perl' is
> requested, Apache redirects to #!/usr/bin/perl. Or something else to
> accomplish the same effect. My ISP doesn't know how to do this,
> without having to move the Perl-module completely.
>
> I'd be very gratefull if anyone could help me out!
One work-around *might* be to put the *NIX shebang in the script and
executing on Windows by simply putting 'perl' in front of the script
(like "c:\perl\bin\perl.exe script.pl"). This won't work too well
through the web server running on Windows, but it *should* work at the
command line.
Or, you could create a link on the Windows PC. Make the directory
structure 'c:\usr\bin' and place the link there pointing to where Perl
really is on your system. Perl will understand, AFAIK. The '\' can
be '/' on a Windows system in Perl - FWIU.
OTOH, I could be wrong about this and hope someone would correct me if
I am.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Authors (and perhaps columnists) eventually rise to the top of
whatever depths they were once able to plumb. -- Stanley
Kaufman
------------------------------
Date: Thu, 13 Nov 2003 13:22:12 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: #!perl instead of #!/usr/bin/perl on a Unix/Apache webserver
Message-Id: <3FB37774.8EA139B9@fujitsu-siemens.com>
joe wrote:
> =
> Hi there!
> =
> Can anyone help me out here. I run my CGI-scripts locally on a Windows
> machine. In the shebang line I put #!c:\www\Perl.exe, but it's also pos=
sible
> to use only #!perl. On my virtual webserver at my ISP's Unix machine I =
have
> to use #!/usr/bin/perl.
AFAIK it is irrelevant _what_ command you put into the shebang line on a
windows system. Windows doesn't know shebang lines (it maybe knows a .pl
extension, though), but the perl interpreter knows how to extract
options (e.g. -w) from the shebang line.
So, you might be able to put the Linux/UN*X command into the shebang
line on a Windows system an that would work.
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Thu, 13 Nov 2003 12:40:58 GMT
From: "joe" <tunmaster@hotmail.com>
Subject: Re: #!perl instead of #!/usr/bin/perl on a Unix/Apache webserver
Message-Id: <uZKsb.110468$di.27351432@amsnews02.chello.com>
Thanks for your input. Because of James' post I realised that I could
install Perl at the exact same address as on my ISP's webserver. I didn't
realise that #!c:\usr\bin\perl.exe is interpreted the same as
#!/usr/bin/perl on a Windows machine. Fortunately it is!
Thanks again!
Joe
------------------------------
Date: 13 Nov 2003 06:46:26 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: a Post-script to flocking question
Message-Id: <bov9c2$53m$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Dick Rosser:
> Sorry, I also meant to ask if there is any
> error trapping with flock. If a second person
> accesses the database befor the first persons lock
> is in place, is the database corrupted. How does one
> work around this?
You don't, but flock() does. This is exactly the scenario it is used
for. Since locks are usually only advisable, both parties accessing the
database have to use flock(). If there is already a lock on it, the
other process will block until the lock is released. You can also do
non-blocking locks in which case flock() returns a false value if the
file is already locked:
use Fcntl qw(:flock);
...
flock FH, LOCK_EX|LOCK_NB or die $!;
This can be used for allowing the waiting processes do something useful
in the meantime:
while (! flock FH, LOCK_EX|LOCK_NB) {
warn $!;
# do some useful stuff here
}
# and now we have the lock and can work with the file
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 13 Nov 2003 05:50:59 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: count of 1s in a binary number
Message-Id: <776e0325.0311130550.1b61499@posting.google.com>
Fred <fJogham@yahoo.com> wrote in message news:<3FAB4BB6.7020503@yahoo.com>...
> if there is not a function that takes a scalar or array and count a
> given charcter. I am trying to come up with a code
>
>
> my $bit1 = "011001010";
> my @bit2 = qw /01 00 11 01 00/;
> print size_of($bit1), "\n";
> print size_of(@bit2), "\n";
>
> sub size_of {
> my $tmp = shift;
> my $i = 0;
> foreach my $j (split //, $tmp) {
> if ( $j == 1 ) { $i++ };
> }
> return $i;
> }
I tightened up my code a bit this seems to work.... Benchmark would
probably be pretty good compared to looping solutions (assuming I
understand yuor requirements)...
Have fun!
G
#!/usr/bin/perl -wd
$_ = '101010111010101';
my @b = qw(01 10 11 01 01 00);
my $r = ones($_);
print "scalar: $r\n";;
$r = ones(\@b);
print "array: $r\n";;
exit 0;
sub ones
{my $b = $_[0];
$b = join '', @$b if ref $b;
$b =~ s/(.)(?=.)/$1+/g;
return eval $b;
}
------------------------------
Date: Thu, 13 Nov 2003 15:02:25 +0100
From: "Steffen Beyer" <steffen.beyer@de.bosch.com>
Subject: Re: count of 1s in a binary number
Message-Id: <bp02th$n1j$1@ns2.fe.internet.bosch.com>
"Ilya Zakharevich" <nospam-abuse@ilyaz.org> wrote in message =
news:bou912$18o8$1@agate.berkeley.edu...
> > > sub count_bits ($) {
> > > my $x =3D shift;
> > > my $shift =3D 1;
> > > for my $mask (0x55555555, 0x33333333, 0x0f0f0f0f, 0x00ff00ff, =
0x0000ffff) {
> > > $x =3D ($x & $mask) + (($x >> $shift) & $mask);
> > > $shift *=3D 2;
> > > }
> > > $x;
> > > }
> > I hadn't seen this before, thanks for bringing it up.
> I think I discussed it on one of Perl lists circa mid-90s. [Of
> course, even then it was possible to find prior art; today, with
> google, you get many hits on these numbers...]
I've seen it on www.snippets.org back when I implemented this in my
Bit::Vector module.
Note that the different algorithms may score differently in C due to
differences in overhead between C and Perl.
Best regards,
Steffen Beyer
------------------------------
Date: Thu, 13 Nov 2003 12:28:43 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Data Dumper guidance
Message-Id: <bova38$1j5p2l$1@ID-191136.news.uni-berlin.de>
Hi Everyone,
Need some help in Data::Dumper.
What I want to do is sort this array (@arr) based on the first element of
the sub-arrays.
So I want finally is @sarr = ([3,2], [5,0], [6,3]);
Here is the code:
use Data::Dumper;
my @arr = ([5,0], [3,2], [6,3]);
print Data::Dumper->Dump(\@arr);
my @sarr = sort { $a <=> $b} @arr;
print Data::Dumper->Dump(\@sarr);
TIA
--
------------------------------
Date: Thu, 13 Nov 2003 09:04:26 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Data Dumper guidance
Message-Id: <slrnbr6i8k.hde.ak+usenet@otaku.freeshell.org>
In article <bova38$1j5p2l$1@ID-191136.news.uni-berlin.de>, Kasp wrote:
> Hi Everyone,
>
> Need some help in Data::Dumper.
> What I want to do is sort this array (@arr) based on the first element of
> the sub-arrays.
> So I want finally is @sarr = ([3,2], [5,0], [6,3]);
So, really this has nothing to do with Data::Dumper, but with
sorting.
> Here is the code:
> use Data::Dumper;
> my @arr = ([5,0], [3,2], [6,3]);
> print Data::Dumper->Dump(\@arr);
> my @sarr = sort { $a <=> $b} @arr;
That will sort on the array references in @arr.
You want this:
my @sarr = sort { $a->[0] <=> $b->[0]} @arr;
--
Andreas Kähäri
------------------------------
Date: Thu, 13 Nov 2003 16:08:04 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Re: Data Dumper guidance
Message-Id: <bovmui$1j4of1$1@ID-191136.news.uni-berlin.de>
> You want this:
> my @sarr = sort { $a->[0] <=> $b->[0]} @arr;
Thanks Andreas.
--
------------------------------
Date: Thu, 13 Nov 2003 05:32:47 -0700
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: DBD-Oracle-1.14
Message-Id: <3FB379EF.3080404@comcast.net>
You do not have the Oracle client installed.
diego wrote:
> Hi,
>
> I'm not able to create the Makefile for DBD module. The OS is winXP,
> I'm using ActivePerl 5.8.0 and DBD-Oracle-1.14. DBI are already
> installed. Oracle Home is c:\oracle\ora92. Perl is in c:\Perl.
> When I type:
> perl Makefile.pl
>
> the console output is following:
>
>
>
> Using DBI 1.38 installed in C:/Perl/site/lib/auto/DBI
>
> Configuring DBD::Oracle ...
>
>
>>>> Remember to actually *READ* the README file!
>>>
> Especially if you have any problems.
>
> Using Oracle in C:/oracle/ora92
> Found header files in rdbms/demo.
>
>
> *********************************************************
> I can't find the header files I need in your Oracle installation. You
> probably need to install some more Oracle components. I'll keep going,
> but the compile will probably fail. See README.clients for more
> information.
>
> *********************************************************
>
> Found oci directory
> Using OCI directory 'oci'
> Found oci/lib/MSVC/oramts.lib library
> *** Warning: Colons in the current directory path
> (C:/perl/DBDOracle114) may cause problems
> Unable to find required Oracle OCI files for the build. Please check
> That you have your OCI installed in your oracle home (C:/oracle/ora9)
> Directory and that it has the following files (and probably more):
>
> C:/oracle/ora92\oci\include\oratypes.h
> C:/oracle/ora92\oci\lib\MSVC\.lib
>
> Please install OCI or send comments back to dbi-users@perl.org
> If you have an OCI directory other than oci.
>
> At Makefile.pl line 263
>
>
> THANK YOU IN ADVANCE FOR THE HELP. PLEASE DON'T LET ME ALONE!!!
--
Ron Reidy
Oracle DBA
------------------------------
Date: 12 Nov 2003 23:07:17 -0800
From: oliver.gassner@web.de (Oliver G)
Subject: Re: fetchall_arrayref into bind_param_array
Message-Id: <eabb4cb1.0311122307.47060b3e@posting.google.com>
James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<20031112210510.0555df96.jwillmore@remove.adelphia.net>...
> On 12 Nov 2003 07:19:19 -0800
> oliver.gassner@web.de (Oliver G) wrote:
>
> > Hey Folk,
> > i have to do a Job to extract Data from one Database into another.
> > So i thing this is a Job for Perl. I make a fetchall_arrayref then
> > i insert this block into the other Database with bind_param_array.
> > Now i have the Array of Arrays but i can't extract an Array of
> > Column to use bind_param_array.
> >
> > Have any one a Idea?
> >
> > Any Hint welcome!
>
> Hint: post some code.
> Hint: *read* the DBI documentation (perldoc DBI)
> Hint: as some of my previous posts have shown, improper use of terms
> can be hazardious to your code :-)
>
> HTH
>
> --
> Jim
>
> Copyright notice: all code written by the author in this post is
> released under the GPL. http://www.gnu.org/licenses/gpl.txt
> for more information.
>
> a fortune quote ...
> There's a fine line between courage and foolishness. Too bad
> it's not a fence.
Thank you her the Code:
$DW_dbh = DBI->connect("dbi:ODBC:TestIHLE", "TEST2", "TEST2")
or die "$DBI::errstr\n";
$hSel = $DW_dbh-> prepare ("select * from temptab");
$hSel->execute();
$rows=$hSel->fetchall_arrayref();
$hHosttab = $DW_dbh-> prepare ("insert into temptab values (?,?,?)");
$hHosttab->bind_param_array (1,$rows[here i have the Problem
undef?][0]);
$hHosttab->bind_param_array (2,$rows[here i have the Problem
undef?][1]);
$hHosttab->bind_param_array (3,$rows[here i have the Problem
undef?][2]);
$hHosttab->execute_array({ArrayTupleStatus => \my @tuple_status });
What i wanna do is to fetch a Array and Insert into a Table. But i
can't extract the column of all rows!
------------------------------
Date: Thu, 13 Nov 2003 11:40:22 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: fetchall_arrayref into bind_param_array
Message-Id: <20031113063623.4a7323ad.jwillmore@remove.adelphia.net>
On 12 Nov 2003 23:07:17 -0800
oliver.gassner@web.de (Oliver G) wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote in message
> news:<20031112210510.0555df96.jwillmore@remove.adelphia.net>...
> > On 12 Nov 2003 07:19:19 -0800
> > oliver.gassner@web.de (Oliver G) wrote:
<snip>
*PLEASE* read the posting guidelines.
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
> Thank you her the Code:
<snip>
I guess this is actually what you have, right?
---------------------------------------------------------------------
--
#this is a comment
$DW_dbh = DBI->connect("dbi:ODBC:TestIHLE", "TEST2", "TEST2")
or die "$DBI::errstr\n";
$hSel = $DW_dbh-> prepare ("select * from temptab");
$hSel->execute();
$rows=$hSel->fetchall_arrayref();
$hHosttab = $DW_dbh-> prepare ("insert into temptab values (?,?,?)");
#[here i have the Problem undef?]
$hHosttab->bind_param_array (1,$rows [0]);
#[here i have the Problem undef?]
$hHosttab->bind_param_array (2,$rows[1]);
#[here i have the Problem undef?]
$hHosttab->bind_param_array (3,$rows[2]);
$hHosttab->execute_array({ArrayTupleStatus => \my @tuple_status });
---------------------------------------------------------------------
------
Some may not think this is an efficent way to do this, but I do it
because it's more readable. Plus, the results of the query will not
return properly if the schema of the data source changes - which will
signal a change to the script.
Try (untested):
------------------------------------------------------------
$DW_dbh =
DBI->connect(
"dbi:ODBC:TestIHLE", "TEST2", "TEST2",
{RaiseError=>1}
)
or die "$DBI::errstr\n";
$hSel = $DW_dbh-> prepare ("select * from temptab");
#are you *sure* you want to select from temptab and then,
#insert the results into temptab - the *same* place the
#select results came from?
$hHosttab =
$DW_dbh-> prepare ("insert into temptab values (?,?,?)");
$hSel->execute();
#change the *_column_name" to the name of
#each column - for example:
#if the first column is "dog", then
#"$ref->{first_colum_name}" should read
#"$ref->{dog}"
while(my $ref = $fetchrow_hashref){
$hHosttab->execute(
"$ref->{first_colum_name}",
"$ref->{second_column_name}",
"$ref->{third_column_name",
{ArrayTupleStatus => \my @tuple_status }
);
}
------------------------------------------------------------
Notice that I coded for hash references versus array references. For
me, I prefer to use hash references, because I should *know* the
database schema - especially if I'm going to do inserts with the data
latter on. I'm not saying it's more efficent or that you can't use
array refererences - I do it because I can read easily what's going on
with the code.
You should consider changing the table name for the insert statement
you posted - unless you *like* infinite loops :-)
HTH and does what you want it to do.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"Dying is a very dull, dreary affair. And my advice to you is to
have nothing whatever to do with it." -- W. Somerset Maugham
------------------------------
Date: 13 Nov 2003 05:25:27 GMT
From: ctcgag@hotmail.com
Subject: Re: fetchrow not proceeding beyond 9th record
Message-Id: <20031113002527.558$DV@newsreader.com>
dn_perl@hotmail.com (dn_perl@hotmail.com) wrote:
> I am trying to fetch rows using $sth->fetchrow.
> If I run my sql query from 'sqlplus' prompt, it returns 58 unique
> records. But if I do :
>
> while ($sth->fetchrow())
>
> the loop is terminated after processing only 9 (not 58) records.
>
> Why could this be happening?
I don't know what fetchrow is. Is it a deprecated synonym for
fetchrow_array?
If so, then as soon as you return a false value (0,empty string,etc.) your
loop will test false and exit.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Thu, 13 Nov 2003 13:53:15 GMT
From: "Anand" <karigna_no@verizon.net>
Subject: File Append Issue
Message-Id: <f1Msb.33513$y95.5307@nwrdny01.gnilink.net>
After looking at a number of sources which have little to say on appending
to a file I came up with the following piece of code to append a sentence to
a file:
#!/usr/bin/perl
#open(FILE, ">>test1.html") || die $!;
#print FILE "This is a test line added to the file, <br>\n";
$line_to_write="I've appended a line to a file !";
$file_name="test1.html";
open(DAT,">>$file_name");
print DAT "$line_to_write\n";
close(DAT);
The commented and uncommented sections do the same thing though, they create
a second file without the .html extender rather than appending to
test1.html. What am I doing wrong here?
A.
------------------------------
Date: Thu, 13 Nov 2003 19:29:37 +0530
From: "Kasp" <kaspREMOVE_CAPS@epatra.com>
Subject: Re: File Append Issue
Message-Id: <bp02se$1j6der$1@ID-191136.news.uni-berlin.de>
"Anand" <karigna_no@verizon.net> wrote in message
news:f1Msb.33513$y95.5307@nwrdny01.gnilink.net...
> The commented and uncommented sections do the same thing though, they
create
> a second file without the .html extender rather than appending to
> test1.html. What am I doing wrong here?
Try specifying the absolute path to the file test1.html
Also remember to "close" the file once you are done working with it.
Add the following two lines to your code at the top:
use strict;
use warnings;
--
------------------------------
Date: Thu, 13 Nov 2003 08:24:22 +0000 (UTC)
From: zorg@zed.com (the zorg )
Subject: Re: how to erase \r or \015 in win32?
Message-Id: <3fb33e8b.346998109@news.btopenworld.com>
On Wed, 12 Nov 2003 03:20:31 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>news.hinet.net wrote:
>> i want to erase ^M in then end of lines.
>> but i can do this in win32.
>>
>> $_=~s/\r//g; #but \r still exist
>
>Not for me.
>
> $_ = "First line\r\nSecond line\r\n";
yes but have you not just typed a backslash and an 'r' and not the
control character "\r"?
> print length, "\n";
> s/\r//g;
You are just removing every character 'r' by replacing every occurence
of 'r' with "nothing".
> print length, "\n";
>
>Printed result:
>25
>23
Z
>
>--
>Gunnar Hjalmarsson
>Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
------------------------------
Date: Thu, 13 Nov 2003 10:20:09 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: how to erase \r or \015 in win32?
Message-Id: <3FB34CC9.1F08DE14@fujitsu-siemens.com>
the zorg wrote:
[ ] You have a real name
[X] You don't have a real name
> > $_ =3D "First line\r\nSecond line\r\n";
> =
> yes but have you not just typed a backslash and an 'r' and not the
> control character "\r"?
[ ] You know Perl
[X] You don't know Perl.
> > print length, "\n";
> > s/\r//g;
> =
> You are just removing every character 'r' by replacing every occurence
> of 'r' with "nothing".
[ ] You know Perl
[X] You don't know Perl.
Try to read a book about Perl, then read it again and try to understand
what it says, then, if you succeed, get a real name and come back.
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Thu, 13 Nov 2003 10:11:53 +0000
From: Jim Mozley <jim.mozley@exponential-e.com>
Subject: Re: Installation of a perl module
Message-Id: <3FB358E9.6050004@exponential-e.com>
mistletoe wrote:
> Command : ppm install DBI.ppd
>
> Error: No valid repositories: Error: 500 Can't connect to
> ppm.ActiveState.com:80 (connect: Unknown error) at C:/Program
> Files/Perl/site/lib/PPM/Repository.pm line 84 Error: 500 Can't connect
> to ppm.ActiveState.com:80 (connect: Unknown error) at C:/Program
> Files/Perl/site/lib/PPM/Repository.pm line 84
>
> Line 84: "my $soap_result = $client->ppm_protocol;"
>
> How do I correct this error?
Is the issue one of connectivity to the activestate pp site, form the
error above it seems to indicate you cannot connect to it. Is there a
firewall or similar preventing you from reaching it?
Jim
------------------------------
Date: 13 Nov 2003 03:43:04 -0800
From: ranjithvenkatesh@hotmail.com (mistletoe)
Subject: Re: Installation of a perl module
Message-Id: <f08a2d40.0311130343.1a2fc192@posting.google.com>
I am able to connect to the ppm.activestate.com website.
I was able to download the perl modules that i required individually.
However after unzipping and unpacking them I don't know which files
and which folders to put into the lib folder.
Ranjith.
------------------------------
Date: Thu, 13 Nov 2003 11:52:55 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Installation of a perl module
Message-Id: <20031113064911.29e1af90.jwillmore@remove.adelphia.net>
On 13 Nov 2003 03:43:04 -0800
ranjithvenkatesh@hotmail.com (mistletoe) wrote:
> I am able to connect to the ppm.activestate.com website.
>
> I was able to download the perl modules that i required
> individually. However after unzipping and unpacking them I don't
> know which files and which folders to put into the lib folder.
>
> Ranjith.
That wasn't the point of my post. The point was you stated you got
an error while using PPM. And *maybe* you should consult the
ActiveState Knowledgebase to see what you could do to correct the
problem.
PPM is not pure Perl - using CPAN is. PPM is something ActiveState
put together - so you don't have to compile the module yourself.
This all, of course, is just my take on it :-)
To answer directly where to put the files - again, you should go to
ActiveState's web site and see what's posted there - since they put
the whole distribution together. I have a guess, but it's only a
guess. I normally compile the modules or can use PPM through our
firewall at work. So, I have little experience with your issue.
OTOH, does the documentation that came with the ActiveState install
(specifically, PPM) address this situation? I think ActiveState
already thought this situation might arise.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"Die? I should say not, dear fellow. No Barrymore would allow
such a conventional thing to happen to him." -- John
Barrymore's dying words
------------------------------
Date: Thu, 13 Nov 2003 13:11:03 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: Installation of a perl module
Message-Id: <li07rv45os0d0t8vgop5s0jahh52i8bh1b@4ax.com>
On 13 Nov 2003 03:43:04 -0800, ranjithvenkatesh@hotmail.com
(mistletoe) wrote:
>I am able to connect to the ppm.activestate.com website.
You probably need to set your proxy server, as detailed
in the Activeperl documentation:
file:///C:/Perl/html/faq/ActivePerl-faq2.html#ppm_and_proxies
>I was able to download the perl modules that i required individually.
>However after unzipping and unpacking them I don't know which files
>and which folders to put into the lib folder.
Don't do that. It won't work except by accident.
------------------------------
Date: Thu, 13 Nov 2003 20:51:33 +1100
From: King <kingsman22004@yahoo.com>
Subject: installing a perl module
Message-Id: <3FB35425.3060909@yahoo.com>
Hello
I installed a Bit::Vector
$
$ pon <isp>
$ /bin/su
# cd /usr/local/bin
# perl -MCPAN -e 'install "Bit::Vector"'
.
.
.
/usr/bin/make install -- OK
# perl -MBit::Vector -e 1
# exit
$ perl prog/p2.pl # a program that uses Bit::Vector
Can't locate Bit/Vector.pm in @INC (@INC contains:
/usr/local/lib/perl5/5.8.1/i686-linux /usr/local/lib/perl5/5.8.1
/usr/local/lib/perl5/site_perl/5.8.1/i686-linux
/usr/local/lib/perl5/site_perl/5.8.1 /usr/local/lib/perl5/site_perl .)
at prog/p2.pl line 4.
BEGIN failed--compilation aborted at prog/p2.pl line 4.
$
my question is, is it ok to /bin/su the install a module from CPAN or
install any thing for that matter or I need to logout and login as root?
and if so why /bin/su does not do?
what should I do from here?
thanks
------------------------------
Date: Thu, 13 Nov 2003 12:22:09 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: installing a perl module
Message-Id: <bovt1h$r8p$2@wisteria.csv.warwick.ac.uk>
news@group.com wrote:
> Hello
> I installed a Bit::Vector
>
> $
> $ pon <isp>
> $ /bin/su
> # cd /usr/local/bin
> # perl -MCPAN -e 'install "Bit::Vector"'
<sigh>
I thought I explained this.
Type, as root
perl -v
. The first perl in root's PATH is /usr/bin/perl, not
/usr/local/bin/perl. You need to make sure you invoke the right perl.
*Don't* get this wrong again, or you risk updating Debian's perl
modules, which is apparently what we are trying to avoid.
> my question is, is it ok to /bin/su the install a module from CPAN or
> install any thing for that matter or I need to logout and login as root?
No, su(1) is fine.
> what should I do from here?
Perhaps learn a little more about using Linux before you try
installing software by hand?
Ben
--
. | .
\ / The clueometer is reading zero.
. .
__ <-----@ __ ben@morrow.me.uk
------------------------------
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 5791
***************************************