[17249] in Perl-Users-Digest
Perl-Users Digest, Issue: 4671 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 20 06:05:36 2000
Date: Fri, 20 Oct 2000 03:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <972036316-v9-i4671@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 20 Oct 2000 Volume: 9 Number: 4671
Today's topics:
Re: Array stuck within a loop <bart.lateur@skynet.be>
Bug in Date::Calc Day_of_Week <ubl@schaffhausen.de>
Re: capture CTRL-C, CTRL-Z <jalford12@yahoo.co.uk>
Re: converting a binary file to ascii <lr@hpl.hp.com>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Re: File Locking and CGI jeacocks@uk.ibm.com
Re: File::Find pruning <bart.lateur@skynet.be>
Re: finding mode and median of an array of numbers <bart.lateur@skynet.be>
Finding two words in any order in string? <sba@ocegr.fr>
Re: Finding two words in any order in string? nobull@mail.com
Re: Finding two words in any order in string? <julien.quint@xrce.xerox.com>
God, this is like hard work... <themoriman@ntlworld.com>
Re: God, this is like hard work... <themoriman@ntlworld.com>
Re: God, this is like hard work... (Bernard El-Hagin)
Re: God, this is like hard work... <ubl@schaffhausen.de>
Re: God, this is like hard work... (Bernard El-Hagin)
Help DBI/ DBD mysql ghorghor@my-deja.com
Re: Help DBI/ DBD mysql ghorghor@my-deja.com
Re: Help DBI/ DBD mysql (Anders Hertz)
Re: Help DBI/ DBD mysql ghorghor@my-deja.com
how can I get data from a file into variable? <gapming@hotmail.com>
Re: how can I get data from a file into variable? (Bernard El-Hagin)
Re: How to find out the number of lines in a flat file. (Bernard El-Hagin)
Re: http referer manipulation nobull@mail.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 20 Oct 2000 09:05:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Array stuck within a loop
Message-Id: <l500vssdb6id8fj77d9q6deao57n0hsk62@4ax.com>
bhui wrote:
>I have used regex to separate a large string into a bunch of little ones,
>within one of these little ones I have created and array using split to
>converting each character into the array.
>
>The problem is when I go parsing throught this array and get to the end or
>an unassigned value it hangs my while loop.
>
>I suspect whats happening it the string i converted into an array does not
>have a /n to tell the while loop we are at the end. Is there a way to
>terminate the while if the array is unassigned ??
Easy.
>>until (@tags[$char_to] =~ /\,/)
>> {
>> $char_to++ ;
>> }
Make this
until ($char_to >= @tags or @tags[$char_to] =~ /\,/)
{
$char_to++ ;
}
But I have the feeling that you're using too much of a C-like mindset.
You don't need to treat a string as an array of characters: use a regex
instead. Much faster.
The sample data certainly did help; but did you have to take such a big
file? Couldn't you just take out one or two example lines? And not post
it as a binary attachment? After all, this is pure text!
>$string =~ (/^(.*?) "(.*?);(.*?)"
>\/REVISION="(.*?)"(.*?)VCS_TAGS(.*?)\)(.*?)\n.*/) ;
I think you want the lines that start with an uppercase letter. Say so.
if(/^([A-Z]+)\s+"([^"])+;([^"]+)"\s+(.*)/) {
# got me such a line!
> {
> $ui = $1 ;
> $item_id_tmp = $2 ;
> $old_rev = $3 ;
> $real_rev = $4 ;
> $cmd1 = $5 ;
> $vcs_tags = $6 ;
> $user_filename = $7 ;
my($ui, $item_id_tmp, $old_rev, $rest) = ($1, $2, $3, $4);
Or, better still, put the LHS inside the condition for the "if", wit
hthe RHS being the regex.
Now, the rest of the line ($rest) seems to be very nicely structured:
it's always a slash, followed by a word which is followed by nothinhg, a
"=" and a parameter between quotes, or a "=" and a set of parameters
between parentheses. It seems to me that this can be neetly pt into a
hash:
my %record = $rest =~ m!/(\w+)(?:=("[^"]*"|\(.*?\)))?!g;
Now, if the attributes part (the VCS_* things) can contain a ")", you
need the more detailed regex to match the stuff between "(" and ")".
This regex would be a lot like this one:
my %attributes = $record{ATTRIBUTES}
=~ /(\w+)(?:=("[^"]*"|\[[^]]+\]))?/g;
This:
use Data::Dumper;
print Dumper \%record, \%attributes;
can show you what this gets out of the data.
Using this on one of your example strings, I see the bugger, in
%attributes:
'VCS_TAGS' =>
'["BAKER_II_ALA1","BAKER_II_ALA2","BAKER_II_ALB1","BAKER_II_ALA3","BAKER_II_ALC1","BAKER_II_AMA1","BAKER_II_AMB1","BAKER_II_ALD1","AKER_II_ALE1","BAKER_II_ALE1","BAKER_II_AMA2","BAKER_II_ALF1","BAKER_II_ALD2","BAKER_II_AMC1","BAKER_II_AMD1","BAKER_II_ANA1","BAKER_II_AMB2","BAKER_II_ALG3","BAKER_II_001P","BAKER_II_ANB1","BAKER_II_ANC1","BAKER_II_AMC2","BAKER_II_AMD2","BAKER_II_AND1","BAKER_II_ANE1","BAKER_II_AME2","BAKER_II_ANF1","BAKER_II_020P","BAKER_II_ANG1","BAKER_II_ANH1","BAKER_II_AMF2","BAKER_II_080P","BAKER_II_ANI1","BAKER_II_ANJ1","BAKER_II_ANK1","BAKER_II_ANL1","BAKER_II_631P","BAKER_11_APA1","BAKER_II_APA1","BAKER_II_632P","BAKER_II_APB1","BAKER_II_633P","BAKER_II_DYNAMIC_FE","BAKER_II_AQA1","BAKER_II_AQB1","BAKER_II_AQC1","BAKER_II_634P","BAKER_II_ARA1","BAKER_II_ARB1","BAKER_II_ARC1","BAKER_II_ARD1","BAKER_II_ARE1","BAKER_II_ARF1","BAKER_II_ARG1","BAKER_II_SIGNAL_OPEN","BAKER_II_670P"]'
Well, if this exists, you can do
my @list = ($attributes{VCS_TAGS} || "") =~ /("[^"]+")/g;
For this example, this gave me a list of 56 quoted strings. I'm not sure
what you want to do with this, but I think you can take it from here:
reconstruct a set of output strings in the same format as the source
string, based on extracts of these data structures.
--
Bart.
------------------------------
Date: Fri, 20 Oct 2000 11:00:39 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Bug in Date::Calc Day_of_Week
Message-Id: <39F009B8.95492410@schaffhausen.de>
Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------EE37FBFADAA3D9DB3BC9061A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
there seems to be a bug in Date::Calc's Day_of_Week function.
For Dates before 1980 it seems to deliver the wrong days.
I've asked 3 colleages for the day of their birth and had them
call their mothers to verify it, and for all of them Date::Calc
delivers wrong results.
BTW: my Macintosh Date/Time control panel (the Perl script is
running on Linux) has similar problems.
My Questions are whether:
- this is a bug?
- Germany left out a coupla leap years ?-)
- the US left out a coupla leap years?
- there are any solutions for this problem? (maybe a small UNIX app)
- anybody knows about a correct calendar on the internet which
I can use to verify dates?
Your help is appreciated!!!
malte
--------------EE37FBFADAA3D9DB3BC9061A
Content-Type: text/x-vcard; charset=us-ascii;
name="ubl.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Visitenkarte fŸr Malte Ubl
Content-Disposition: attachment;
filename="ubl.vcf"
begin:vcard
n:Ubl;Malte
tel;cell:+49 173 9237521
tel;fax:+49 4121 472938
tel;home:+49 4121 438297
tel;work:+49 4121 472964
x-mozilla-html:FALSE
url:http://www.schaffhausen.de
org:Schaffhausen | Interactive
adr:;;Daimlerstrasse 17;Elmshorn;;25337;Germany
version:2.1
email;internet:ubl@schaffhausen.de
title:Developer for web-based applications
x-mozilla-cpt:;1
fn:Malte Ubl
end:vcard
--------------EE37FBFADAA3D9DB3BC9061A--
------------------------------
Date: Fri, 20 Oct 2000 10:42:18 +0100
From: "JA" <jalford12@yahoo.co.uk>
Subject: Re: capture CTRL-C, CTRL-Z
Message-Id: <PuUH5.2096$YW2.152255@e420r-sjo1.usenetserver.com>
incase you don't, like me, have access to perldoc...
#
# set up a signal handler
#
$SIG{INT} = \&signal_handler;
$SIG{TERM} = \&signal_handler;
$program_stop_flag = 0;
<lots of code>
do something if ($program_stop_flag); # check the
signal handler flag
<lots of code>
sub signal_handler {
my $signal_name = shift;
print "This program has been zapped - shutting down\n";
$program_stop_flag = 1;
}
------------------------------
Date: Thu, 19 Oct 2000 23:38:04 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: converting a binary file to ascii
Message-Id: <MPG.1459882afabc7e3798ae4d@nntp.hpl.hp.com>
In article <39EF845D.CBCCFC3A@pauls.seanet.com>,
pauls_spam_no@pauls.seanet.com says...
> Larry Rosler wrote:
> > Apparently your input file has 8-byte alignment screwed up. If this is
> > due to a "\12" in the binary data, it can only be because the file was
> > *written* as a text file, so what was written was really "\15\12".
> >
> > To verify this conjectore, test again without the (correct) 'binmode
> > NEW;' statement. Then any "\15\12" sequence in the input file will be
> > converted (back?) to "\12" and the program should work.
...
> open(BIN,'<purebin.dat');
> open(OUT,'>decoded.dat');
> binmode(BIN);
> $count = 0;
> seek(DAT, $point, 0);
> while (read(BIN,$in,8))
> {
> $count ++;
> $foo = unpack("H*",$in);
> $bar = unpack("d",$in);
> print OUT "$count $foo $bar\n";
> }
> close(BIN);
> close(OUT);
>
> Any thoughts on how to cure myself of this CR, lF dis-ease??
>
> By the way, the file I am struggling with is written by a cad tool (a SPICE
> simulator). The format is entirely due to the guys at the simulator factory!!
Evidently the file was written using text mode, and you say you can't do
anything about it. So, as I said above, try reading it without the
binmode(). Unfortunately, now the I/O system will think that a "\cZ"
byte is EOF, so you will very likely be hosed that way.
Maybe you should use binmode() and read the entire file into a scalar
and do this:
s/\15(=\12)//g;
Then process the scalar using 8-byte substrings, or at once with unpack
'd*'.
> Thanks for all your help to-date, thanks a whole lot!
You're welcome.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 20 Oct 2000 08:27:12 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_972030297@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://home.eu.org/~jari/ema-keys.html
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs
XEmacs/Emacs, is available to various platforms:
o Unix:
If you don't have one, bust your sysadm.
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
Emacs resources at http://home.eu.org/~jari/emacs-elisp.html
o W9x/NT:
http://www.gnu.org/software/emacs/windows/ntemacs.html
Emacs Perl Modules
Cperl -- Perl programming mode
.ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
.<olson@mcs.anl.gov> Bob Olson (started 1991)
.<ilya@math.ohio-state.edu> Ilya Zakharevich
Major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
starndard in newest Emacs.
TinyPerl -- Perl related utilities
.http://home.eu.org/~jari/tiny-tools-beta.zip
.http://home.eu.org/~jari/emacs-tiny-tools.html
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Load source code into Emacs, like Devel::DProf.pm
o Grep through all Perl manpages (.pod)
o Follow POD manpage references to next pod page with TinyUrl
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o TinyUrl is used to jump to URLs (other pod pages, man pages etc)
mentioned in POD pages. (It's a general URL minor mode)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in the tgz mentioned above]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example in the tgz (ema-tigr.ini) that shows
how to set up datatbases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to run the find for you, You can adjust
recursive grep options, ignored case, add user grep options.
You can get `igrep.el' module from <kevinr@ihs.com>. Ask for copy.
Check also ftp://ftp.ihs.com/pub/kevinr/
TinyCompile -- Browsing grep results in Emacs *compile* buffer
TinyCompile is minor mode for *compile* buffer from where
you can collapse unwanted lines, shorten the file URLs
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: 20 Oct 2000 08:53:41 GMT
From: jeacocks@uk.ibm.com
Subject: Re: File Locking and CGI
Message-Id: <8sp16l$4jg$1@sp4en10.hursley.ibm.com>
>Irrelevant. You don't mention where the program runs. Does it always
>run on the same server?
>If so, you can create a local lockfile not on AFS. Open/lock that file,
>then if successful, open the AFS file and deal with it. When done,
>close the AFS file and then release the local lock.
That would work fine if I only required that the lock be maintained while
the current process was running. Unfortunatly the CGI program locks the
file, then sends some data to the user, then exits. It then starts again
as a new process when the user sumbits the form, it should then write out
the new data and unlock the file. All locks created by flock() get
destroyed when a process ends this is not what I need.
------------------------------
Date: Fri, 20 Oct 2000 07:37:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: File::Find pruning
Message-Id: <e8svuso867tsd4a1qcrhp814c4bkgpoqro@4ax.com>
James Taylor wrote:
>I recently had a task which I thought would be ideal for File::Find
>but I was disappointed with it's behaviour in regard to pruning.
>I am therefore tempted to write my own recursive routine, but you'll
>probably tell me that I'm doing something wrong and that File::Find
>will do what I want after all. Here's what I want to do:
>
>I have a hierarchy of newsgroup directories to scan, and below each
>group in the structure are further (numbered) directories containing
>article files. Also in each group directory is an article index file
>called .overview which I want to process in my script. Having processed
>the .overview file I want to move on to the next newsgroup without
>scanning all the article subdirectories of the current group.
I think you misunderstand how pruning works in File::Find; or else, I
do. AFAIK, setting $File::Find::prune *only* works if your current file
is a directory. You can prevent File::Find from actually entering this
one directory. What you want to prune it when you find a certain file,
namely the '.overview' file. That won't work.
Here's my solution: For every subdirectory, check for the '.overview'
file yourself. If it exist, set $File::Find::prune in order to skip
subdirectories.
my $root = "/newsgroups";
my $offset = length($root)+1;
find sub {
if(-d) {
if(-e "$File::Find::name/.overview") {
my $newsgroup = substr($File::Find::name, $offset);
print "Got an overview file: $newsgroup\n";
$File::Find::prune = 1;
}
}, $root;
Caveat: this code is untested.
--
Bart.
------------------------------
Date: Fri, 20 Oct 2000 07:47:49 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: finding mode and median of an array of numbers
Message-Id: <52uvus4urg6dlfmujh9nti57se7n6mtvcm@4ax.com>
Godzilla! wrote:
>Alright, I'll level with you boys, this one time.
>I did not 'get' those definitions anywhere. I made
>them up.
Gee. And all other docs I can find seem to (roughly) agree with your
definition.
Here's one example:
http://library.thinkquest.org/17038/admission/math/meanmodemedian-question.html
the mean is the average of a set of numbers; to calculate it, you take
the sum of each of the terms in the set and then you divide that sum
by the total number of items you have in your set.
the mode is a number in a set that occurs most often.
the median is the middlemost number in a set of numbers if the set is
arranged in order.
--
Bart.
------------------------------
Date: Fri, 20 Oct 2000 09:27:43 +0200
From: Stephane Barizien <sba@ocegr.fr>
Subject: Finding two words in any order in string?
Message-Id: <39EFF3EF.6C2B2D6C@ocegr.fr>
Hi,
I have a big multiline (embedded \n's) string in $str.
I want to check if $str contains two (or more, but that's next) words,
in any order...
What's better than:
foo.*bar|bar.*foo
?
TIA
(I've intentionally not taken the word boundary aspect into account)
------------------------------
Date: 20 Oct 2000 08:37:07 +0100
From: nobull@mail.com
Subject: Re: Finding two words in any order in string?
Message-Id: <u93dhrq4oh.fsf@wcl-l.bham.ac.uk>
Stephane Barizien <sba@ocegr.fr> writes:
> I want to check if $str contains two (or more, but that's next) words,
> in any order...
>
> What's better than:
>
> foo.*bar|bar.*foo
The best solution is two (or more) independant regexps.
$str =~ /foo/ && $str =~ /bar/
But if you _must_ do it with one:
$str =~ /^(?=.*foo).*bar/
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 20 Oct 2000 11:16:29 +0200
From: Julien Quint <julien.quint@xrce.xerox.com>
Subject: Re: Finding two words in any order in string?
Message-Id: <thk8b3oosy.fsf@lautaret.grenoble.xrce.xerox.com>
Stephane Barizien <sba@ocegr.fr> writes:
> I have a big multiline (embedded \n's) string in $str.
> I want to check if $str contains two (or more, but that's next) words,
> in any order...
> What's better than:
>
> foo.*bar|bar.*foo
Maybe /foo/ && /bar/ ? You would have to experiment to decide if it's better,
but I would do it this way. I guess two simple regex matches could be faster
than a more complicated one.
--
Julien
------------------------------
Date: Fri, 20 Oct 2000 09:13:30 +0100
From: "The Moriman" <themoriman@ntlworld.com>
Subject: God, this is like hard work...
Message-Id: <d9TH5.87$bL1.3118@news6-win.server.ntlworld.com>
Why did they make Perl so difficult to learn?
I've read the FAQ's , the Perl documentation (that seems to be excellent,
but assumptions are made about what you already know, which in my case
appears to be a big fat nothing)
I can write full blown win32 apps in ASM but can't get a grip on Javascript
at all :-(
Any way, enough griping..
Very basic question, I have an array such that I 'know' that $myarray[2] has
the value of 'good old Bob' (without quotes),
How do I search the array to find 'good old Bob'?
I tried
for ($i=0; $i<=$#myarray; $i++){
if ($myarray[$i] eq 'good old Bob') {
print <<END;
$myarray[$i]<br>
END
}
else {
print <<END;
Not this one<br>
END
}
}
(the html header and footer are set up properly) but all I get is a list of
'Not this one'.
I've tried putting 'good old Bob' in "" instead of '', I've tried == instead
of eq (but didn't expect that to work anyway).
Can anybody put me out of my misery?
Also, what language should I read up on to gain the knowledge that the Perl
documentation assumes I should have?
Thanks for any and all help
TMMan
------------------------------
Date: Fri, 20 Oct 2000 09:18:15 +0100
From: "The Moriman" <themoriman@ntlworld.com>
Subject: Re: God, this is like hard work...
Message-Id: <UcTH5.91$bL1.3244@news6-win.server.ntlworld.com>
The Moriman <themoriman@ntlworld.com> wrote in message
news:d9TH5.87$bL1.3118@news6-win.server.ntlworld.com...
> I can write full blown win32 apps in ASM but can't get a grip on
Javascript
> at all :-(
Sorry about that, god only knows where 'Javascript ' came from. I must get
the keys on the keyboard fixed ;-)
please insert Perl for Javascript.
------------------------------
Date: 20 Oct 2000 08:29:27 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: God, this is like hard work...
Message-Id: <slrn8v00ld.28m.bernard.el-hagin@gdndev25.lido-tech>
On Fri, 20 Oct 2000 09:13:30 +0100, The Moriman
<themoriman@ntlworld.com> wrote:
[snip]
>Very basic question, I have an array such that I 'know' that $myarray[2] has
>the value of 'good old Bob' (without quotes),
>
>How do I search the array to find 'good old Bob'?
>I tried
>
> for ($i=0; $i<=$#myarray; $i++){
> if ($myarray[$i] eq 'good old Bob') {
> print <<END;
> $myarray[$i]<br>
>END
> }
> else {
> print <<END;
> Not this one<br>
>END
> }
> }
I copy-and-pasted your code, added the lines:
$myarray[0] = 'klsdkfj';
$myarray[1] = 'good old Bob';
$myarray[2] = 'iweioweioioweweio';
at the beginning and ran it from the command line. The result:
Not this one<br>
good old Bob<br>
Not this one<br>
Which means that something else is wrong. BTW, a more Perlish way to
write that for loop is:
foreach my $element (@myarray){
if ($element eq 'good old Bob'){
.
.
.
#etc
Cheers,
Bernard
--
perl -le'
($B,$e,$r,$n,$a,$r,$d)=q=$B$e$r$n$a$r$d==~m;
\$(.);xg;print$B.$e.$r.$n.$a.$r.$d;'
------------------------------
Date: Fri, 20 Oct 2000 11:18:27 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: God, this is like hard work...
Message-Id: <39F00DE4.70CAA09E@schaffhausen.de>
Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------01EDC7650890D259B133AB9F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
The Moriman schrieb:
>
> Why did they make Perl so difficult to learn?
Because it's only for cool people ;-)
> I've read the FAQ's , the Perl documentation (that seems to be excellent,
> but assumptions are made about what you already know, which in my case
> appears to be a big fat nothing)
> I can write full blown win32 apps in ASM but can't get a grip on Javascript
> at all :-(
>
> Any way, enough griping..
>
> Very basic question, I have an array such that I 'know' that $myarray[2] has
> the value of 'good old Bob' (without quotes),
>
> How do I search the array to find 'good old Bob'?
> I tried
>
> for ($i=0; $i<=$#myarray; $i++){
> if ($myarray[$i] eq 'good old Bob') {
> print <<END;
> $myarray[$i]<br>
> END
> }
> else {
> print <<END;
> Not this one<br>
> END
> }
> }
I think yours should work but this is kinda nicer:
my @ARRAY;
$ARRAY[20] = "someString";
foreach my $element (@ARRAY) {
if($element = "someString") {
print "Yahoo!\n"
} else {
print "Well, maybe next time :-(\n"
}
}
There is probably an even better/faster/cooler way to do this
but this works for sure (Well, there might be some syntax errors
in there, but...)
Hope this helps,
malte
--------------01EDC7650890D259B133AB9F
Content-Type: text/x-vcard; charset=us-ascii;
name="ubl.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Visitenkarte fŸr Malte Ubl
Content-Disposition: attachment;
filename="ubl.vcf"
begin:vcard
n:Ubl;Malte
tel;cell:+49 173 9237521
tel;fax:+49 4121 472938
tel;home:+49 4121 438297
tel;work:+49 4121 472964
x-mozilla-html:FALSE
url:http://www.schaffhausen.de
org:Schaffhausen | Interactive
adr:;;Daimlerstrasse 17;Elmshorn;;25337;Germany
version:2.1
email;internet:ubl@schaffhausen.de
title:Developer for web-based applications
x-mozilla-cpt:;1
fn:Malte Ubl
end:vcard
--------------01EDC7650890D259B133AB9F--
------------------------------
Date: 20 Oct 2000 10:00:46 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: God, this is like hard work...
Message-Id: <slrn8v060h.28m.bernard.el-hagin@gdndev25.lido-tech>
On Fri, 20 Oct 2000 11:18:27 +0200, Malte Ubl <ubl@schaffhausen.de> wrote:
[snip]
>I think yours should work but this is kinda nicer:
>
>my @ARRAY;
>
>
>$ARRAY[20] = "someString";
>
>foreach my $element (@ARRAY) {
> if($element = "someString") {
^^^^^^^^^^^^^^^^^^^^^^^
> print "Yahoo!\n"
> } else {
> print "Well, maybe next time :-(\n"
> }
>}
That will always print "Yahoo". The condition should read:
if ($element eq "someString") or
if ($element == somenumber) when comparing numbers.
Cheers,
Bernard
--
perl -le'
($B,$e,$r,$n,$a,$r,$d)=q=$B$e$r$n$a$r$d==~m;
\$(.);xg;print$B.$e.$r.$n.$a.$r.$d;'
------------------------------
Date: Fri, 20 Oct 2000 06:50:26 GMT
From: ghorghor@my-deja.com
Subject: Help DBI/ DBD mysql
Message-Id: <8sopvi$gg6$1@nnrp1.deja.com>
hello
i have a big problem,
i have a primary serveur who have all my scripts perl and apache
i have my new DB serveur with mysql 3.22.32
I would connect to the 2nd server via perl scripts
for testing i use this :
# Interface DBI pour mysql
use DBI;
# Paramètres mysql/DBI
$datasource='database=toto;host=216.MMM.MMM.MMM;port=3306;mysql_compress
ion= 1';
$username='tutu';
$password='tata';
$driver='mysql';
$dbh = DBI->connect("dbi:$driver:$datasource", $username, $password); if
(!defined($dbh))
{
print "erreur $!\n";
# "Mysql semble ne plus fonctionner\n";
exit();
}
print "ok";
$rc = $dbh->disconnect;
it doesn't work and i recieve this :
"Transport endpoint is not connected"
WHY ?
NOTA : the IP is correct, the user tut have privileges on database with
host : IP of my primary serveur
the password is correct
Can you help me ?
i add that the DB serveur haven't apache running, nor than perl
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 20 Oct 2000 07:59:05 GMT
From: ghorghor@my-deja.com
Subject: Re: Help DBI/ DBD mysql
Message-Id: <8sou08$k66$1@nnrp1.deja.com>
In article <8sopvi$gg6$1@nnrp1.deja.com>,
ghorghor@my-deja.com wrote:
> hello
>
> i have a big problem,
> i have a primary serveur who have all my scripts perl and apache
> i have my new DB serveur with mysql 3.22.32
>
> I would connect to the 2nd server via perl scripts
> for testing i use this :
>
> # Interface DBI pour mysql
> use DBI;
>
> # Paramètres mysql/DBI
>
>
$datasource='database=toto;host=216.MMM.MMM.MMM;port=3306;mysql_compress
> ion= 1';
> $username='tutu';
> $password='tata';
> $driver='mysql';
>
> $dbh = DBI->connect("dbi:$driver:$datasource", $username, $password);
if
> (!defined($dbh))
> {
>
> print "erreur $!\n";
> # "Mysql semble ne plus fonctionner\n";
> exit();
>
> }
> print "ok";
> $rc = $dbh->disconnect;
>
> it doesn't work and i recieve this :
> "Transport endpoint is not connected"
>
> WHY ?
>
> NOTA : the IP is correct, the user tut have privileges on database
with
> host : IP of my primary serveur
> the password is correct
>
> Can you help me ?
> i add that the DB serveur haven't apache running, nor than perl
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
i modifie some code
$dbh = DBI->connect("dbi:$driver:$datasource", $username, $password) or
die "Can't connect to mysql database: $DBI::errstr\n";
and i have this now :
Can't connect to mysql database: Unknown MySQL Server Host
(host=216.MMM.MMM.MMM)(0)
??? can someone help me
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 20 Oct 2000 09:20:48 GMT
From: a_hertz@removethis.yahoo.com (Anders Hertz)
Subject: Re: Help DBI/ DBD mysql
Message-Id: <39f00dfc.11215704@news.internord.dk>
On Fri, 20 Oct 2000 07:59:05 GMT, ghorghor@my-deja.com wrote:
>> NOTA : the IP is correct, the user tut have privileges on database
>with
>> host : IP of my primary serveur
>> the password is correct
I am no expert either but should'nt host be the server running mySql ?
>>
>i modifie some code
>$dbh = DBI->connect("dbi:$driver:$datasource", $username, $password) or
>die "Can't connect to mysql database: $DBI::errstr\n";
>
>and i have this now :
>Can't connect to mysql database: Unknown MySQL Server Host
>(host=216.MMM.MMM.MMM)(0)
Anders
------------------------------
Date: Fri, 20 Oct 2000 09:49:43 GMT
From: ghorghor@my-deja.com
Subject: Re: Help DBI/ DBD mysql
Message-Id: <8sp4fm$olr$1@nnrp1.deja.com>
In article <39f00dfc.11215704@news.internord.dk>,
a_hertz@removethis.yahoo.com (Anders Hertz) wrote:
> On Fri, 20 Oct 2000 07:59:05 GMT, ghorghor@my-deja.com wrote:
>
> >> NOTA : the IP is correct, the user tut have privileges on database
> >with
> >> host : IP of my primary serveur
> >> the password is correct
>
> I am no expert either but should'nt host be the server running mySql ?
>
> >>
> >i modifie some code
> >$dbh = DBI->connect("dbi:$driver:$datasource", $username, $password)
or
> >die "Can't connect to mysql database: $DBI::errstr\n";
> >
> >and i have this now :
> >Can't connect to mysql database: Unknown MySQL Server Host
> >(host=216.MMM.MMM.MMM)(0)
>
> Anders
>
connection telnet to port 3306 ( mysql )
on the DB serveur work
so there isn't a pb of communication
i have test that on an other machine and it works
so it seems to be the DBD versions that doesn't work
but i have an old version of perl 5.0004
and DBI : 0.93
but i can't install a new version of perl for compatibility
and i not sure that installing a new version of with old perl will
work ??
can you help me ?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 20 Oct 2000 17:14:44 +0800
From: "Arthur" <gapming@hotmail.com>
Subject: how can I get data from a file into variable?
Message-Id: <8sp2a9$hv9$1@news.ctimail.com>
I have a file (e.g. test.log) that the format is:
2000-10-18 5000
2000-10-19 1000
2000-10-20 2000
where the space between the date and the number is a tab.
How can I retreive the number 2000 into a variable? I just want to get the
most bottom one.
Thanks.
------------------------------
Date: 20 Oct 2000 09:40:52 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: how can I get data from a file into variable?
Message-Id: <slrn8v04r4.28m.bernard.el-hagin@gdndev25.lido-tech>
On Fri, 20 Oct 2000 17:14:44 +0800, Arthur <gapming@hotmail.com> wrote:
>I have a file (e.g. test.log) that the format is:
>2000-10-18 5000
>2000-10-19 1000
>2000-10-20 2000
>
>where the space between the date and the number is a tab.
>How can I retreive the number 2000 into a variable? I just want to get the
>most bottom one.
----------------------------------------
#!/usr/bin/perl -w
use strict;
open (IN, "/path/to/test.log") or die $!;
my $var = (split /\t/, (<IN>)[-1])[-1];
----------------------------------------
Cheers,
Bernard
--
perl -le'
($B,$e,$r,$n,$a,$r,$d)=q=$B$e$r$n$a$r$d==~m;
\$(.);xg;print$B.$e.$r.$n.$a.$r.$d;'
------------------------------
Date: 20 Oct 2000 06:34:00 GMT
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: How to find out the number of lines in a flat file.....
Message-Id: <slrn8uvpst.28m.bernard.el-hagin@gdndev25.lido-tech>
On Thu, 19 Oct 2000 16:37:30 -0400, Slim <ShadeyGradey@hotpop.com>
wrote:
>Hello,
>I'm trying to make a image gallery script and I'm using many flat file
>databases..... they all may have more or less lines and I want to know
>how to get the number of lines there are.....
One of the most inspired pieces of code I ever saw on this NG was
Abigail's solution to this problem (I'm ad libbing it since I don't
remember how it went exactly, but the idea is the same):
perl -lpe '}$_=$.;{' <input file>
Cheers,
Bernard
--
perl -le'
($B,$e,$r,$n,$a,$r,$d)=q=$B$e$r$n$a$r$d==~m;
\$(.);xg;print$B.$e.$r.$n.$a.$r.$d;'
------------------------------
Date: 20 Oct 2000 08:52:53 +0100
From: nobull@mail.com
Subject: Re: http referer manipulation
Message-Id: <u94s27q5n5.fsf@wcl-l.bham.ac.uk>
OK this is off-topic but Jeff Zucker <jeff@vpservices.com> writes
things that AFAIK are factually incorrect:
> EM wrote:
> >
> > I use this code to redirect the browser to an url
> >
> > print "Content-type: text/html\n";
> > print "Location: $url\n\n";
> >
> > this works fine
>
> Really? It is contrary to the specs.
What specs would those be?
> You should issue either a content-type or a location header, not
> both.
According to HTTP standard a redirect response from server to client
"SHOULD" contain an entity. According to the CGI specification the
redirect response from CGI script to server "MAY" do so unless it's an
internal redirect. (By implication if the CGI script fails to provide
one the HTTP server should generate one). Obviously any response that
contains an entity must also have a content-type. Conversely the CGI
is not supplying the entity then it should not emit a content-type
header.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4671
**************************************