[24544] in Perl-Users-Digest
Perl-Users Digest, Issue: 6722 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 24 06:05:47 2004
Date: Thu, 24 Jun 2004 03:05:06 -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 Thu, 24 Jun 2004 Volume: 10 Number: 6722
Today's topics:
[Newbie] Stupid problem need simple answer (Array & Reg <daedalus@videotron.ca>
Re: [Newbie] Stupid problem need simple answer (Array & <daedalus@videotron.ca>
Re: [Newbie] Stupid problem need simple answer (Array & <Joe.Smith@inwap.com>
Re: [Newbie] Stupid problem need simple answer (Array & (Anno Siegel)
Re: DBD::Sybase, FreeTDS problem <mpeppler@peppler.org>
Graphs using perl (Ram Laxman)
Re: Graphs using perl <nobull@mail.com>
Re: Help! - Need a CGI redirect which passes a querystr <noreply@gunnar.cc>
Re: Idiom for partitioning array? (Anno Siegel)
Re: noob trying to learn where to start? <daedalus@videotron.ca>
Re: repeated calculations everyday <usenet@morrow.me.uk>
Re: repeated calculations everyday <Joe.Smith@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Jun 2004 03:34:36 -0400
From: "Daedalus" <daedalus@videotron.ca>
Subject: [Newbie] Stupid problem need simple answer (Array & RegExp)
Message-Id: <BsvCc.530$uY3.534@wagner.videotron.net>
Keep in mind that I'm fresh one week years-old Perl newbie... thanks
I just need some information about what happen when :
my @string_list; #lets say that this array contain a couple of string, 3:
(the street, a book, theater)
foreach my $string (@string_list){
if ($string =~ s/(^the\b)|(^a\b)|//i){
$string_list[++$#string_lis] = $string
}
}
When I write: if ($string =~ s/(^the\b)|(^a\b)|//i)..., do I actually
replacing the string within @string_list (since $string is passed by
"foreach" from one of the string of @string_list) I'm asking cause I thought
that it would add the new strings to the array without touching what was
already there. So I would end with this list as @string_list (the street, a
book, theater, street, book).
But when try this, it overwrite and add. So it gives me ( street, book,
theater, street, book).
What am I doing wrong?
Thanks
DAE
------------------------------
Date: Thu, 24 Jun 2004 03:47:24 -0400
From: "Daedalus" <daedalus@videotron.ca>
Subject: Re: [Newbie] Stupid problem need simple answer (Array & RegExp)
Message-Id: <CEvCc.905$uY3.384@wagner.videotron.net>
Well I think I was guessing right cause if I write this instead:
foreach (@string_list){
my $string = $_;
if ($string =~ s/(^the\b)|(^a\b)//i){
$string_list[++$#string_lis] = $string
}
}
I get the wanted result, but I would like someone to confirm that.
thanks
DAE
"Daedalus" <daedalus@videotron.ca> a écrit dans le message de news:
BsvCc.530$uY3.534@wagner.videotron.net...
> Keep in mind that I'm fresh one week years-old Perl newbie... thanks
> I just need some information about what happen when :
>
> my @string_list; #lets say that this array contain a couple of string,
3:
> (the street, a book, theater)
>
> foreach my $string (@string_list){
> if ($string =~ s/(^the\b)|(^a\b)//i){
> $string_list[++$#string_lis] = $string
> }
> }
>
> When I write: if ($string =~ s/(^the\b)|(^a\b)|//i)..., do I actually
> replacing the string within @string_list (since $string is passed by
> "foreach" from one of the string of @string_list) I'm asking cause I
thought
> that it would add the new strings to the array without touching what was
> already there. So I would end with this list as @string_list (the street,
a
> book, theater, street, book).
> But when try this, it overwrite and add. So it gives me ( street, book,
> theater, street, book).
> What am I doing wrong?
>
> Thanks
> DAE
>
>
------------------------------
Date: Thu, 24 Jun 2004 08:03:46 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: [Newbie] Stupid problem need simple answer (Array & RegExp)
Message-Id: <BVvCc.75775$2i5.19115@attbi_s52>
Daedalus wrote:
> Keep in mind that I'm fresh one week years-old Perl newbie... thanks
> I just need some information about what happen when :
>
> my @string_list; #lets say that this array contain a couple of string, 3:
> qw(the street, a book, theater);
>
> foreach my $string (@string_list){
> if ($string =~ s/(^the\b)|(^a\b)|//i){
> $string_list[++$#string_lis] = $string
> }
> }
>
> When I write: if ($string =~ s/(^the\b)|(^a\b)|//i)..., do I actually
> replacing the string within @string_list (since $string is passed by
> "foreach" from one of the string of @string_list)
Yes. You are modifying the array element as they are being processed
since the foreach variable is aliased to the array element and not
a copy of the array element.
The line inside the if() is better written as
push @string_list, $string;
-Joe
------------------------------
Date: 24 Jun 2004 08:40:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: [Newbie] Stupid problem need simple answer (Array & RegExp)
Message-Id: <cbe41a$8eo$1@mamenchi.zrz.TU-Berlin.DE>
Daedalus <daedalus@videotron.ca> wrote in comp.lang.perl.misc:
> "Daedalus" <daedalus@videotron.ca> a écrit dans le message de news:
> BsvCc.530$uY3.534@wagner.videotron.net...
[top-post rearranged]
> > Keep in mind that I'm fresh one week years-old Perl newbie... thanks
> > I just need some information about what happen when :
> >
> > my @string_list; #lets say that this array contain a couple of string,
> 3:
> > (the street, a book, theater)
> >
> > foreach my $string (@string_list){
> > if ($string =~ s/(^the\b)|(^a\b)//i){
> > $string_list[++$#string_lis] = $string
> > }
> > }
> >
> > When I write: if ($string =~ s/(^the\b)|(^a\b)|//i)..., do I actually
> > replacing the string within @string_list (since $string is passed by
> > "foreach" from one of the string of @string_list) I'm asking cause I
> thought
> > that it would add the new strings to the array without touching what was
> > already there. So I would end with this list as @string_list (the street,
> a
> > book, theater, street, book).
> > But when try this, it overwrite and add. So it gives me ( street, book,
> > theater, street, book).
> > What am I doing wrong?
>
> Well I think I was guessing right cause if I write this instead:
>
> foreach (@string_list){
> my $string = $_;
> if ($string =~ s/(^the\b)|(^a\b)//i){
What are the capturing parentheses in the pattern for? s/^the\b|^a\b//i
does the same thing.
> $string_list[++$#string_lis] = $string
^^
Typo here. Don't re-type code, copy/paste it.
Also, "++$#string_list" would be better written as (scalar)
"@string_list".
> }
> }
> I get the wanted result, but I would like someone to confirm that.
Your code (in all variants) has another problem. You are not supposed
to change an array while running a for-loop over it. (See "foreach" in
perlsyn, I suppose.) That it appears to work in this instance doesn't
mean it will with other versions of Perl.
There are lots of ways to repair this, one is
push @string_list, map /(?:the\b|a\b)?\s*(.*)/i, @string_list;
Instead of deleting the unwanted part, this captures the wanted part.
I have also changed the regex so that it also catches trailing
whitespace with the articles.
Anno
------------------------------
Date: Thu, 24 Jun 2004 08:12:41 +0200
From: Michael Peppler <mpeppler@peppler.org>
Subject: Re: DBD::Sybase, FreeTDS problem
Message-Id: <pan.2004.06.24.06.12.40.53440@peppler.org>
On Wed, 23 Jun 2004 14:15:34 -0700, Daniel Berger wrote:
> Hi all,
>
> Perl 5.8.2
> Solaris 9
> FreeTDS 0.63 (20040622)
> DBI 1.42
> DBD::Sybase 1.04
>
> I installed FreeTDS 0.63 successfully. I can definitely connect using
> tsql. However, when I try this simple script I get an error.
>
> use strict;
> use warnings;
> use DBI;
> use DBD::Sybase;
>
> my $login = "user";
> my $passwd = "xxxx";
> my $server = "SOME-SERVER";
> my $host = "somehost";
> my $port = 1030;
>
> $ENV{SYBASE} = "/usr/local";
> my $dbh =
> DBI->connect("dbi:Sybase:server=$server;host=$host;port=$port",$login,
> $passwd);
>
> $dbh->disconnect();
>
> The error is: This version of OpenClient doesn't support CS_SERVERADDR at
> /opt/csw/lib/perl/site_perl/DBD/Sybase.pm line 87.
DBD::Sybase doesn't use the host/port method of connecting to a database
server. Instead it uses a logical server name defined in the interfaces
file (or in the freetds.conf file.)
The only exception is when using Sybase OpenClient 12.5.1 or later, where
the API has the ability to by-pass the interfaces file.
If "SOME-SERVER" is defined in your freetds.conf file you can simply
remove the host/port info from the DSN and it should work correctly.
Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler@peppler.org http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.peppler.org/resume.html
------------------------------
Date: 23 Jun 2004 22:59:00 -0700
From: ram_laxman@india.com (Ram Laxman)
Subject: Graphs using perl
Message-Id: <24812e22.0406232159.3353b4cc@posting.google.com>
Hi all,
I am having the csv file.Does anybody knows how to make a bar
graph/chart extracting some fields from the csv file?
For exp:
"empno","age","sal"
1,23,10000
2,3,5
I want to plot a graph between empno and sal.
Ram Laxman
------------------------------
Date: 24 Jun 2004 07:56:24 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Graphs using perl
Message-Id: <u93c4lgwpf.fsf@wcl-l.bham.ac.uk>
ram_laxman@india.com (Ram Laxman) writes:
> I am having the csv file.Does anybody knows how to make a bar
> graph/chart extracting some fields from the csv file?
I've never had cause to do this, but if I did I'd probably use one
module with "CSV" in the name and another with "Graph" in the name.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 24 Jun 2004 11:11:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help! - Need a CGI redirect which passes a querystring value
Message-Id: <2jvk8iF167949U1@uni-berlin.de>
Matt Garrish wrote:
> Both mod_perl and aspx scripts only need to compile once (and with
> mod_perl you can precompile the modules).
Don't take for granted that mod_perl is an available option. The OP in
this thread used the wording "the Windows server I am hosted on".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 24 Jun 2004 07:57:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Idiom for partitioning array?
Message-Id: <cbe1ho$5se$1@mamenchi.zrz.TU-Berlin.DE>
Brad Baxter <bmb@ginger.libs.uga.edu> wrote in comp.lang.perl.misc:
> On Wed, 23 Jun 2004, Anno Siegel wrote:
> > Brad Baxter <bmb@ginger.libs.uga.edu> wrote in comp.lang.perl.misc:
> > > On Wed, 23 Jun 2004, Anno Siegel wrote:
[...]
> > > > map [ splice @a, 0, $n], 0 .. $#a/$n;
> > >
> > > Can't beat that.
> >
> > It isn't entirely correct, however. If @a is empty (and $n > 1), it
> > returns one empty slice, but should return none. That's because
> > the implicit int( $#a/$n) is 0, not something negative, when $#a = -1.
>
> Which behavior the non-destructive version also exhibits.
>
> ... if @a;
>
> perhaps?
That, or map [ splice @a, 0, $n], 1 .. $#a/$n + 1;
Anno
------------------------------
Date: Thu, 24 Jun 2004 02:49:18 -0400
From: "Daedalus" <daedalus@videotron.ca>
Subject: Re: noob trying to learn where to start?
Message-Id: <%NuCc.166682$IT.2364642@wagner.videotron.net>
I'm a newb myself, learning Perl for maybe a week now. I started with
O'Reilly's "Learning Perl (3rd Ed) and I must say that it's pretty good
starting point. With the standard Perl Documentation of course.
DAE
<foxhoundIV@yahoo.com> a écrit dans le message de news:
VuqCc.165954$Ly.35985@attbi_s01...
> Hi all,
>
> Would like to learn perl but not sure where to even start. Does anyone
have suggestions
> good books or sites, etc? I have some vb experience and no unix experience
(working on that too).
> Any help is very much appreaciated.
>
> TIA!!
>
>
------------------------------
Date: Thu, 24 Jun 2004 04:37:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: repeated calculations everyday
Message-Id: <cbdlqv$6he$1@wisteria.csv.warwick.ac.uk>
Quoth shalinij1@yahoo.com (Shalini Joshi):
>
> The following is the logic-structure of the code I am attempting to
> write:
>
> if (today is the first of the month)
> {
>
> Read all files with name containing SYSMT03.xxxxx.txt
> #x denotes arbitrary value
perldoc -f glob
> Each file contains information pertaining to a particular owner. So
> I parse the data no1, y for each user . Now this entire data from all
> these files is to be sorted on the basis of this no1. That is more
> than one user can have the same value for no1.
>
> #The question I ask at this point is, how would I go about doing this
> in perl? #What data structure would I use given this ?
>
> I have to sum the total of y(from various user files) for each no1. I
> call this value BASE1
I would call it BASE0, as Perl starts array numbers and day-of-month
numbers (indeed, ordinals generally) at 0.
my @BASE;
for (<SYSMT03.*.txt>) {
my ($no1, $y) = read_data_from $_;
no warnings 'uninitialized';
$BASE[0]{$no1} += $y;
}
> }
>
> else if (today is not the first day of the week, then for each
> remaining day(recurring calculations)
>
> {
> Read another set of files names containing SYSMT02Axxxx.txt
>
> Again similar information. Now what I will do here is calculate the
> change in BASE and add it to BASE1 to get at BASE2. SImilarly for the
> remaining days.(eg BASE3= BASE2+change3)..
my $mday = (localtime)[3];
for (...) {
my ($no1, $my) = read_data_from $_;
$BASE[$mday]{$no1} = $BASE[$mday - 1]{$no1}
unless exists $BASE[$mday]{$no1};
$BASE[$mday]{$no1} += $y;
}
You can make this structure permanent between runs using the Storable
module.
> }
>
> I am getting stuck right in the beginning itself...where I try and
> match the regular expressions:
>
> I say :
>
> open (ACCOUNT_POSITION, '/home/perlstuff' ) or die "Can't open file:
> $!\n";
Use three-arg open.
Use lexical filehandles.
Don't use unnecessary parens.
Include the filename in the error message.
Probably don't put "\n" on the end of die messages.
I would use a shorter variable name...
open my $ACCT_POS, '<', '/home/perlstuff'
or die "can't open /home/perlstuff: $!";
> <ACCOUNT_POSITION> =~ /.+03\..{5}\.txt
This is a syntax error.
> It doesnt work for some reason although i have the said file in my
> directory. Where am I going wrong on this one???
Define 'doesn't work'. What are you expecting to happen, and what
actually happens?
Ben
--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk
------------------------------
Date: Thu, 24 Jun 2004 07:59:53 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: repeated calculations everyday
Message-Id: <ZRvCc.84721$Hg2.44774@attbi_s04>
Ben Morrow wrote:
> Quoth shalinij1@yahoo.com (Shalini Joshi):
>>I have to sum the total of y(from various user files) for each no1. I
>>call this value BASE1
>
> I would call it BASE0, as Perl starts array numbers and day-of-month
> numbers (indeed, ordinals generally) at 0.
The day-of-week and month-in-year are based at zero (making it easy to
index into an array that translates the array index into a text string),
but day-of-month starts at 1.
-Joe
------------------------------
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 6722
***************************************