[22398] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4619 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 25 06:05:49 2003

Date: Tue, 25 Feb 2003 03:05:08 -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           Tue, 25 Feb 2003     Volume: 10 Number: 4619

Today's topics:
    Re: Checking something to see if it isn't there........ (Anno Siegel)
    Re: editting photos on the fly <sdyck@engr.uvic.ca.spam>
    Re: extract string from another string <pdhze@yahoo.co>
    Re: extract string from another string (Anno Siegel)
    Re: FAQ proposal: Why can't I compare two strings using (Philip Lees)
    Re: FAQ proposal: Why can't I compare two strings using <tore@aursand.no>
        Giving over $37,000 to use their products! 31108 dial911info@yahoo.com
        Giving over $37,000 to use their products! dial911info@yahoo.com
        Guestbook Pro 1.0 (PCMedics)
    Re: Long strings're causing problems <noreply@gunnar.cc>
    Re: LWP Requests <skippyinhi@aol.com>
        Not a Perl guy but need help <bushong@OCF.Berkeley.EDU>
    Re: Not a Perl guy but need help <ian@WINDOZEdigiserv.net>
    Re: Not a Perl guy but need help <bushong@OCF.Berkeley.EDU>
    Re: Not a Perl guy but need help (Anno Siegel)
    Re: Parsing line into hash... <hamish@travellingkiwi.com>
    Re: Parsing line into hash... (Sara)
    Re: Reading tab delimited files into a hash. <damian@qimr.edu.au>
    Re: Splice problem <tore@aursand.no>
    Re: translate ( tr ) question (Tad McClellan)
    Re: translate ( tr ) question (Tad McClellan)
    Re: translate ( tr ) question <s_grazzini@hotmail.com>
    Re: translate ( tr ) question (Tad McClellan)
    Re: translate ( tr ) question <hideki@massassi.net>
    Re: try my program out... (PCMedics)
    Re: try my program out... <tassilo.parseval@post.rwth-aachen.de>
    Re: Using DBI::mysql <geoff.news6@alphaworks.co.uk>
    Re: Using DBI::mysql <geoff.news6@alphaworks.co.uk>
    Re: Using DBI::mysql <tore@aursand.no>
        variable assignment question. help (Louis)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Feb 2003 09:07:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Checking something to see if it isn't there..........
Message-Id: <b3fbop$9e9$1@mamenchi.zrz.TU-Berlin.DE>

Tina Mueller  <usenet@tinita.de> wrote in comp.lang.perl.misc:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > Steven Smolinski  <steven.smolinski@sympatico.ca> wrote in
> comp.lang.perl.misc:
> >>     my $operation = shift or die "No operator given";
> 
> > Yes, that's a common idiom, and it may be applicable here.  However,
> > Taking the OP literally, the question was whether the argument was
> > given at all and scalar @ARGV tests that.  "or" tests if anything
> > substantial (boolean true) was given, which isn't quite the same thing.
> > The difference may well not matter here.
> 
> defined(my $operation = shift) or die "No operator given";

That doesn't discern "func()" from "func( undef)".

Anno


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

Date: Mon, 24 Feb 2003 22:49:09 -0800
From: Steve <sdyck@engr.uvic.ca.spam>
Subject: Re: editting photos on the fly
Message-Id: <3E5B11E5.3B1B541F@engr.uvic.ca.spam>

Thank you to everyone for all the ideas.

Is it also possible add a small icon to a picture?  Say I had a box
where you would enter a coordinate.  The the script would then add the
icon to the bigger picture (the background) at those coordinates, and
generate the new picture.  Forgive me if my terminology is off.  I've
never dabbled in perl before, but this really interests me.

What software do I need to start playing around with this?  Is any of it
free?  

Thanks again for all the help.

Steve

Steve wrote:
> 
> I am probably months behind on this one, but I recently was sent an
> e-mail with a link where I enter my name and it shows up on a picture.
> I tried completely random names to be sure it wasn't just a database of
> millions of pictures.
> 
> So my question is, how do they do this?
> 
> the link was www.kicken.com.  I'll warn you though.  Your name will
> appear on a sign that says "I love <your name>" which is in front of a
> topless girl.  be sure you are of legal age before going to the site.
> 
> any help would be appreciated.
> 
> Steve


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

Date: Tue, 25 Feb 2003 09:46:23 GMT
From: piet <pdhze@yahoo.co>
Subject: Re: extract string from another string
Message-Id: <Usenet.qcddsded@localhost>

John W. Krahn wrote:
> > $teststring =' stuff 650 N other stuff 90N stuff"
> 
> 
> my @extract = $teststring =~ /\b(\d{2,3} *[a-zA-Z])\b/g;
> John

Thanks again John!

Where coudl I find all these switches (\b /g *) explained on internet?
I did a search on google but did not find anything.

Piet



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

Date: 25 Feb 2003 09:53:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: extract string from another string
Message-Id: <b3fee9$bc6$1@mamenchi.zrz.TU-Berlin.DE>

piet  <pdhze@yahoo.co> wrote in comp.lang.perl.misc:
> John W. Krahn wrote:
> > > $teststring =' stuff 650 N other stuff 90N stuff"
> > 
> > 
> > my @extract = $teststring =~ /\b(\d{2,3} *[a-zA-Z])\b/g;
> > John
> 
> Thanks again John!
> 
> Where coudl I find all these switches (\b /g *) explained on internet?

No need for the Internet.  If you have Perl on your computer you
have its complete documentation.  Type "perldoc perlre" at a
command prompt for regular expressions.  For a general introduction,
start with "perldoc perldoc" and "perldoc perl".

Anno


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

Date: Tue, 25 Feb 2003 09:34:38 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <3e5b385c.69650578@news.grnet.gr>

On 24 Feb 2003 18:21:58 +0000, Brian McCauley <nobull@mail.com> wrote:

>"Jürgen Exner" <jurgenex@hotmail.com> writes:
>
>> One of the most frequently asked questions is
>>     "Why can't I compare two strings using == ?"
>> 
>> Suggested answer:
>> The operator "==" compares the numerical values of its operands.
>> Chances are you want to compare the textual values in which case you should
>> use the operator "eq" instead. For further details please check "perldoc
>> perlop".
>
>But surely that's just a special case of the question which the answer
>is "use diagnostics and then perl will tell you".
>
>Unfortuately I can't think of a way to phrase the question.

How about: 'Why don't my equality tests work right?'

Phil
-- 
Ignore coming events if you wish to send me e-mail


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

Date: Tue, 25 Feb 2003 11:52:32 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: FAQ proposal: Why can't I compare two strings using == ?
Message-Id: <pan.2003.02.25.10.25.29.73653@aursand.no>

On Tue, 25 Feb 2003 09:34:38 +0000, Philip Lees wrote:
>> Unfortuately I can't think of a way to phrase the question.

> How about: 'Why don't my equality tests work right?'

I agree that this question should be answered in the FAQ, but I don't see
this question as _one_ question.

The FAQ should rather try to answer something like "why don't my use of an
operator work as expected" and then refer to 'perldoc perlop' and the use
of 'use diagnostics'.

However, this might be of no use to new users, as they don't know that
they 'an operator' is what they're looking for an answer about.  Or?

Just my thoughts.


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/



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

Date: Tuesday, 25 Feb 2003 01:14:02 -0600
From: dial911info@yahoo.com
Subject: Giving over $37,000 to use their products! 31108
Message-Id: <25020301.1402@yahoo.com>

Invest Less than $700 and will make nearly $9000 in one year! No selling at
all PERIOD to make nearly $9000!  

Make only 2 sales of less than $700 in 8 months with no more selling EVER AGAIN and do nothing else AT ALL to make almost $40,000 in one year. This opportunity is 100% legal in ALL states and in 183 countries worldwide.

No gimmicks. No inventory. Well-grounded and proven company. Everyone gets paid! All checks are GOOD and received on time. Available in 138 countries. Email me now for info.      

dial911info@yahoo.com


 


:7?gs


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

Date: Tuesday, 25 Feb 2003 00:41:50 -0600
From: dial911info@yahoo.com
Subject: Giving over $37,000 to use their products!
Message-Id: <25020300.4150@yahoo.com>

Invest Less than $700 and will make nearly $9000 in one year! No selling at
all PERIOD to make nearly $9000!  

Make only 2 sales of less than $700 in 8 months with no more selling EVER AGAIN and do nothing else AT ALL to make almost $40,000 in one year. This opportunity is 100% legal in ALL states and in 183 countries worldwide.

No gimmicks. No inventory. Well-grounded and proven company. Everyone gets paid! All checks are GOOD and received on time. Available in 138 countries. Email me now for info.      

dial911info@yahoo.com


 



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

Date: 25 Feb 2003 01:52:09 -0800
From: sales@pcmedix.org (PCMedics)
Subject: Guestbook Pro 1.0
Message-Id: <e826f4aa.0302250152.3e3bf00f@posting.google.com>

Guestbook pro is a unique guestbook, it allows the web site designer
to have it blend into any web site as if it was written just for that
site, including all logos, fonts, colors and layouts. Our product uses
templates for the header, footer & messages. This makes it stand out
above all else.

  Check it out, and let us know what other features we need to add or
helps find any bugs it may have. Thanks for your time.

http://www.pcmedix.org/gbpro/index.html


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

Date: Tue, 25 Feb 2003 10:39:11 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Long strings're causing problems
Message-Id: <b3feif$1k06jn$1@ID-184292.news.dfncis.de>

Benjamin Goldberg wrote:
> aybikem wrote:
>>Would it be a problem while transfering big chunks of data (long
>>strings) the system can not handle the job? and than give cgi-bin
>>database errors?
> 
> The CGI protocol can handle data of any size.

But not necessarily HTTP. Unlike the POST method for transferring data, 
the GET method has typically a built-in limit of about 1,000 bites. Is 
the form possibly calling the GET method?

/ Gunnar

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



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

Date: Tue, 25 Feb 2003 07:19:13 GMT
From: "scott" <skippyinhi@aol.com>
Subject: Re: LWP Requests
Message-Id: <RNE6a.30962$_J5.2152@nwrddc01.gnilink.net>

As Sharon already said use a tool to analyze the data that is being sent
when you brwse it with a normal browser. Often I have found that this
reveals things that I missed.

I use a packet analyzer for mine the specifically looks at HTTP
transactions.

Regards,
Scott



"Smiley" <smiley@uvgotemail.com> wrote in message
news:v5elafall1sea8@corp.supernews.com...
> > you're not telling us enough... elaborate a little and perhaps we can
> > help...
>
> Well, I've explained some of this in my earlier post.  The website is set
up
> with a searchable database which I would like to grab information from.
The
> online script only accepts Post, and uses form buttons using Post to take
> users to the Next and Previous screens in the search results.
>
> I'm using LWP to grab that information, putting in the necessary variables
> via Post, and this works for the first screen of the search results.
> However, I can't seem to retrieve the subsequent pages.  It seems that the
> first page keeps repeating and I'm not sure what I need to change in order
> to correct that.
>
> The first page of the results is actually not the same script as for the
> second page.  It links to a new script called results.asp, and ads a new
> variable for each page called intCurrentpage and also Action=Next+Items.
>
> I've got my Perl script set up to loop through the number of pages in the
> results and change intCurrentpage each time.  At the end of the loop it
> changes $req to point to results.asp, changes the content, and updates
$res
> appropriately (variable names taken from perldoc)
>
> Yet it's still pulling in the same data from the same page at each loop.
>
> Is that enough information for you?
>
>
>
>




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

Date: Tue, 25 Feb 2003 07:35:09 +0000 (UTC)
From: Michael Bushong <bushong@OCF.Berkeley.EDU>
Subject: Not a Perl guy but need help
Message-Id: <b3f6bd$l03$1@agate.berkeley.edu>

I realize this might annoy some people, but here goes...

I am not a Perl guy, but I need a little help with some stuff I need to
do for work.  As it is late, I cannot exactly call anayone from there.
If you happen to be online and reading this AND are willing to help with
a few basic questions, I would be much obliged.

Please respond by email so as not to spam this group any more than
necessary.  

Cheers,

Mike


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

Date: Tue, 25 Feb 2003 09:26:07 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Not a Perl guy but need help
Message-Id: <iidm5vgvg3i1jile41ulibjgtjmu0pm3nj@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Tue, 25 Feb 2003 07:35:09 +0000 (UTC),
Michael Bushong <bushong@OCF.Berkeley.EDU> managed to scribble:

> I realize this might annoy some people, but here goes...
> 
> I am not a Perl guy, but I need a little help with some stuff I
> need to do for work.  As it is late, I cannot exactly call anayone
> from there. If you happen to be online and reading this AND are
> willing to help with a few basic questions, I would be much
> obliged.
> 
> Please respond by email so as not to spam this group any more than
> necessary.  
> 
> Cheers,
> 
> Mike


Well, you did appallingly and need more help than just with Perl.


- - There's no question in your post.
- - No Perl related material in your post
- - Asking fro an e-mail response is just rude!


It appears so far that you're not doing so well doesn't it? I'd hang
on and wait for your callcentre to become available, your post was a
waste of bandwidth in total.. almost on the borders of trolling.



Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPls2rWfqtj251CDhEQKQwQCgwv57tFJ1xhCnAmFIdaL4qGS/ASIAmgIj
JFeLmbwhLPLLohCUG05IZkFy
=AzSt
-----END PGP SIGNATURE-----

-- 
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Tue, 25 Feb 2003 09:44:04 +0000 (UTC)
From: Michael Bushong <bushong@OCF.Berkeley.EDU>
Subject: Re: Not a Perl guy but need help
Message-Id: <b3fdt4$n06$1@agate.berkeley.edu>

Ian.H [dS] <ian@windozedigiserv.net> wrote:
: Well, you did appallingly and need more help than just with Perl.


: - - There's no question in your post.
: - - No Perl related material in your post
: - - Asking fro an e-mail response is just rude!


: It appears so far that you're not doing so well doesn't it? I'd hang
: on and wait for your callcentre to become available, your post was a
: waste of bandwidth in total.. almost on the borders of trolling.

Ahhh, Ian.  You are such a card.  I did not want to inundate the group
with inane questions as I have all of 9 hours of experience with Perl at
this point.  As for trolling, naaah, I think you have that covered tough
guy.  It's always the guys who got picked on because they were chumps
that flex their muscle in newsgroups.  Still feeling a tad inadequate?

If my proper title of my post did not ward you off, then surely you have
the ability to choose whether or not to respond by mail.  So seriously
dude, hone up on your flaming skills because you have nothing.

-Mike



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

Date: 25 Feb 2003 10:35:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Not a Perl guy but need help
Message-Id: <b3fguf$bc6$2@mamenchi.zrz.TU-Berlin.DE>

Michael Bushong  <bushong@OCF.Berkeley.EDU> wrote in comp.lang.perl.misc:
> I realize this might annoy some people, but here goes...
> 
> I am not a Perl guy, but I need a little help with some stuff I need to
> do for work.  As it is late, I cannot exactly call anayone from there.
> If you happen to be online and reading this AND are willing to help with
> a few basic questions, I would be much obliged.
> 
> Please respond by email so as not to spam this group any more than
> necessary.  

Waste of time.  That's not how clpm or most technical newsgroups
operate.

Anno


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

Date: Tue, 25 Feb 2003 10:02:29 +0000
From: Hamish Marson <hamish@travellingkiwi.com>
To: Brian McCauley <nobull@mail.com>
Subject: Re: Parsing line into hash...
Message-Id: <3E5B3F35.1060408@travellingkiwi.com>

Brian McCauley wrote:
> Hamish Marson <hamish@travellingkiwi.com> writes:
> 
> 
>>I have a datafile that contains lines in the following format
>>
>><IDENT> key value
>>
>>e.g.
>>
>>USER HITS fred 22 john 36 joe 33
>>
>>where key value is repeated many times. I want to read the key value
>>pairs into a hash... But am having problems. I'm trying
>>
>>if ((%userhits) = (/^USER HITS(\s(\w+)\s(\d+))+/)) {
>>
>>which matches, but doesn't get the desired result of a hash with the
>>expected numbers in the expected keys...
>>
>>How exactly should I do this?
> 
> 
> In two steps!
> 
> TMTOWTDI but IMHO one of the most idomatic is (TMTOWTDIBIMHOOOTMII?)
> 
>   # First find the string to the right of 'USER HITS'
>   if ( my ($userhits_string) = /^USER HITS\s+(.*)/ ) {
>     # Then split that string
>     %userhits = split /s+/, $userhits_string;
>   }
> 

Thanks Brian & Benjamin. I was too hung up on trying to use a single 
line, and then repeating loop & a reg exp with /g to think about split.


H


-- 

I don't suffer from Insanity... 	| Linux User #16396
	I enjoy every minute of it...	|
					|
http://www.travellingkiwi.com/ 
	|



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

Date: 25 Feb 2003 02:56:07 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Parsing line into hash...
Message-Id: <776e0325.0302250256.23f6bb15@posting.google.com>

Hamish Marson <hamish@travellingkiwi.com> wrote in message news:<3E5A4889.6010105@travellingkiwi.com>...
> I have a datafile that contains lines in the following format
> 
> <IDENT> key value
> 
> e.g.
> 
> USER HITS fred 22 john 36 joe 33
> 
> where key value is repeated many times. I want to read the key value 
> pairs into a hash... But am having problems. I'm trying
> 
> if ((%userhits) = (/^USER HITS(\s(\w+)\s(\d+))+/)) {
> 
> which matches, but doesn't get the desired result of a hash with the 
> expected numbers in the expected keys...
> 
> How exactly should I do this? 

I tried a few tricks that I thought would work, but as is often the
case, it's a struggle to get pipelined processing in Perl. I think
there is a solution here but I can't find it. APL would ace this, but
its a natural Right to Left processor.

$_ = 'TEST DATA cat 1 dog 2 mouse 6 eel 9 moose 4';

  my %h= split /\s+/, s/^TEST\s+DATA\s+//; # doesnt work
  my %h= split /\s+/, (s/^TEST\s+DATA\s+//); # doesnt work
  my %h= split /\s+/, ($_ =~ s/^TEST\s+DATA\s+//); # doesnt work
  my %h= split /\s+/, scalar s/^TEST\s+DATA\s+//; # doesnt work

# curiously this DOES work, which should be the same result as the
trials above?
  s/^TEST\s+DATA\s+//;
  my %h= split /\s+/; 

Grrr might as well use Java if I wanted to double the number of lines
in my code? Well Java would be more like 10x the number of lines, but
I always look for "Less is More" when it comes to lines of code.
However these types of problems are vexing. I must be missing
something.

Gx

Gx


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

Date: 25 Feb 2003 06:52:08 GMT
From: Damian James <damian@qimr.edu.au>
Subject: Re: Reading tab delimited files into a hash.
Message-Id: <slrnb5m4kn.3d3.damian@margay.qimr.edu.au>

On 22 Feb 2003 04:42:27 -0800, Charles R. Thompson said:
> I constantly find myself reading tab delimited files into a hash in a
> method similar to below. I'm realizing now that it's probably not the
> best way to do it but reading through the docs I haven't come across
> anything new:
[code snipped]
[untested]

#!perl
use warnings;
use strict;
my @fields = qw(
  host username password serverfile clientfile logdirectory
  firstname lastname email clientcode sysimg logo hostfilter
);
my $file = 'D:/WEB_LOG_PROCESSING/HOSTS.TXT';

open HOSTS, $file or die "Can't open $file: $!\n";
my %hosts;
while ( <HOSTS> ) {
	chomp;
	next unless s/^CLIENT:(\w+)\t//;
	@{$hosts{ $1 }}{ @fields } = split /\t/;
}
close HOSTS;
__END__

> Surely there is a more efficient way to deal with the tabs and
> whatnot. I'm not familiar with map or grep... never used them but they
> appear from perldoc.com to deal more with arrays or simple hashes so
> I'm not sure how to take the hash method shown to this level. If map
> or grep would help with this, any assistance would be appreciated.

See perlfunc. Using map() might not be called for here -- a drop-in
replacement for the line with the hash slice but using map() instead
would look like something this:

 my @data = split /\t/;
 %{$hosts{ $1 }} = { map { $fields{$_}, $data{$_} }, 0..$#fields };

or

 my $i=0;
 %{$hosts{ $1 }} = { map { $fields{$i++}, $_ }, split /\t/, $_, @fields};

See the entry for split() in perlfunc. 

HTH,

--damian


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

Date: Tue, 25 Feb 2003 11:52:31 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Splice problem
Message-Id: <pan.2003.02.25.10.28.45.757249@aursand.no>

On Tue, 25 Feb 2003 00:26:04 +0100, Tore Aursand wrote:
> my @array = ('aaaaa','bbbbb','ccccc','dd','eeeee','fffff','ggggg');
> my @new   = ();
> 
> foreach my $element ( @array ) {
>     if ( length($element) >= 5 ) {
>         push( @new, $element );
>     }
> }

Hmm.  After some thought I think I might have changed this to code to
something which I _think_ is more readable...?

  foreach my $element ( @array ) {
      next unless ( length($element) >= 5 );
      push( @new, $element );
  }

Oh, well. :)


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/



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

Date: Mon, 24 Feb 2003 23:41:04 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: translate ( tr ) question
Message-Id: <slrnb5m0fg.327.tadmc@magna.augustmail.com>

Taber <taber@gonetstat.com> wrote:
> I need to know how to translate letters higher than 
> J to a number i.e. a=1..z=27
                            ^^
                            ^^

What alphabet are you using?


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


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

Date: Mon, 24 Feb 2003 23:41:43 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: translate ( tr ) question
Message-Id: <slrnb5m0gn.327.tadmc@magna.augustmail.com>

Taber <taber@gonetstat.com> wrote:
> I need to know how to translate letters higher than 
> J to a number i.e. a=1..z=27


   s/[J-Z]/a=1..z=27/g;


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


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

Date: Tue, 25 Feb 2003 05:42:44 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: translate ( tr ) question
Message-Id: <onD6a.34032$Mh3.13584151@twister.nyc.rr.com>

Taber <taber@gonetstat.com> writes:
> I need to know how to translate letters higher than 
> J to a number i.e. a=1..z=27

tr/// can't overwrite one character (the letter)
with two (the digits).

Try s///g, and maybe a hash of letter => number:

  @hash{k..z} = 11..26; 

-- 
Steve

s|[k-z]|[1..26]->[ord(lc $&)-ord 'a']|eig


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

Date: Mon, 24 Feb 2003 23:48:10 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: translate ( tr ) question
Message-Id: <slrnb5m0sq.33i.tadmc@magna.augustmail.com>

Taber <taber@gonetstat.com> wrote:
> I need to know how to translate letters higher than 
> J to a number i.e. a=1..z=27


   s/([j-z])/ ord($1) - ord('a') + 1/ge;


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


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

Date: Tue, 25 Feb 2003 14:13:10 +0900
From: "Hideki Ono" <hideki@massassi.net>
Subject: Re: translate ( tr ) question
Message-Id: <b3evl6$2os$1@news.sfc.keio.ac.jp>

tr/J-Z/10-27/;

"Taber" <taber@gonetstat.com> wrote in message
news:2cae6cde.0302242054.4ade6fcd@posting.google.com...
> I need to know how to translate letters higher than J to a number i.e.
a=1..z=27



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

Date: 25 Feb 2003 02:15:07 -0800
From: sales@pcmedix.org (PCMedics)
Subject: Re: try my program out...
Message-Id: <e826f4aa.0302250215.21bdaf22@posting.google.com>

This is the auther, sorry about the previous messages, where i looked
very anonymouse.. :) anyway I took your advice and put it to CGI, but
its still encoded so as to not allow the source code out. :) thanks
for the advice guys.

http://www.pcmedix.org


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

Date: 25 Feb 2003 10:58:54 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: try my program out...
Message-Id: <b3fi9e$104$1@nets3.rz.RWTH-Aachen.DE>

Also sprach PCMedics:

> This is the auther, sorry about the previous messages, where i looked
> very anonymouse.. :) anyway I took your advice and put it to CGI, but
> its still encoded so as to not allow the source code out. :) thanks
> for the advice guys.

Err, can you please stop flooding this group with this nonsense? Even
though it's probably in vain, but I'll re-hash: As long as the source
can't be seen by the group, your post is off-topic. So either open it up
or tread off.

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: Tue, 25 Feb 2003 08:11:37 -0000
From: "Geoff Soper" <geoff.news6@alphaworks.co.uk>
Subject: Re: Using DBI::mysql
Message-Id: <3e5b2536$0$3411$cc9e4d1f@news.dial.pipex.com>

"Rik Gordon" <rik.gordon@acm.org> wrote in message
news:b3e7rk$cic$1@venus.btinternet.com...
> Hi Geoff,
>
> Firstly you have only *prepared* your SQL statement you need to execute
> with:
>
> $first_name->execute();
>
> You then need to decide how you want the data returned.  Personally I find
> it easiest to return the records using a hashref, as in the following
> example:
>
> while($data=$first_name->fetchrow_hashref())
> {
>   print "$data->{datafieldname}\n";
> }
>
> In the above datafieldname is the name of a field in your database, the
> while loops around all the records returned in your select printing only
> this one field.
>
> If this makes no sense, email me and I'll send you a complete working
> example.

Hi, thanks for your help, that worked fine. I knew about executing the SQL
statement but missed it out of the example I gave, sorry for confusing the
situation. My confusion was how to deal with a single result and whether
using a while loop was an appropriate solution for this case. From what I've
read it looks as it is. I will probably put a count in the while loop to
guard against there being two matches returned.

Thanks again.
Geoff




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

Date: Tue, 25 Feb 2003 08:16:10 -0000
From: "Geoff Soper" <geoff.news6@alphaworks.co.uk>
Subject: Re: Using DBI::mysql
Message-Id: <3e5b2647$0$3413$cc9e4d1f@news.dial.pipex.com>

"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2003.02.24.23.18.01.501140@aursand.no...
> On Mon, 24 Feb 2003 21:55:33 +0000, Geoff Soper wrote:
> > my $first_name = $dbh->prepare ( "SELECT first_name FROM users WHERE
> > username = \'geoff\'");
> >
> > #What do I need here??
>
> Why didn't you read the DBI documentation first?
>
>   'perldoc DBI'
>   'perldoc DBD::mysql'
> Very helpful.  Anyway.  The first thing you should do, is to 'bind' the
> parameters into the SQL query;
>
>   my $username = 'geoff';
>   my $stFirstName = $dbh->prepare('SELECT first_name
>                                    FROM users
>                                    WHERE username = ?');
>   $stFirstName->execute( $username );
>   my ( $firstname ) = $stFirstName->fetchrow();
>   $stFirstName->finish();
>

Is it necessary to bind the parameters into the query? After reading the
documentation I understood that it wasn't necessary so didn't do that in
order to make my example as simple as possible. Certainly the solution given
in another posting didn't bind and appeared to work for my example. My main
problem was what to do given that I was expecting a single results to be
returned as opposed to a group of columns. I perhaps didn't make that clear
enough in my original posting.

Thanks for your help
Geoff




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

Date: Tue, 25 Feb 2003 11:52:31 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Using DBI::mysql
Message-Id: <pan.2003.02.25.10.46.04.945012@aursand.no>

On Tue, 25 Feb 2003 08:16:10 +0000, Geoff Soper wrote:
>> my $username = 'geoff';
>> my $stFirstName = $dbh->prepare('SELECT first_name
>>                                  FROM users
>>                                  WHERE username = ?');
>> $stFirstName->execute( $username );
>> my ( $firstname ) = $stFirstName->fetchrow();
>> $stFirstName->finish();

> Is it necessary to bind the parameters into the query?

Short answer: No.  Long answer: Yes.  In this case, the long answer is the
best one. :)

There are two main reasons that you _should_ bind parameters into the SQL
query.

First of all, performance:  Let's say you wanted to execute basically the
same query many times, but where just a few parameters changed from each
execution;

  my @usernames = qw( geoff john lisa george peter );

  my $stName = $dbh->prepare('SELECT first_name
                              FROM users
                              WHERE username = ?');
  foreach my $username ( @usernames ) {
      $stName->execute( $username );
      my ( $firstname ) = $stName->fetchrow();
  }
  $stName->finish();

This is more efficiant than the most obvious question (ie. putting the
'prepare()' and 'finish()' inside the loop), as the SQL server only needs
to prepare the SQL statement once.  Preparing an SQL statement can be a
tremendeous task. :)

Secondly, character escaping:  When bind'ing parameters into your SQL
query, you don't have to think of escaping special characters.  This will
be done automagically based on the actuall field's type.

One more thing:  There are - as I know - two ways to bind a parameter into
the SQL query.  I've showed you "my way" of doing it, via the 'execute()'
method, but it can also be done this way;

  my $stComplex = $dbh->prepare('SELECT user_id
                                 FROM user
                                 WHERE username = ? AND
                                       cookie = ?');
  $stComplex->execute();
  $stComplex->bind_param( 1, 'geoff' );
  $stComplex->bind_param( 2, 'htWERTYWErhsdrfher');
  my ( $user_id ) = $stComplex->fetchrow();
  $stComplex->finish();

As mentioned, I prefer to bind them via the 'execute()' method.


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/



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

Date: 24 Feb 2003 22:13:47 -0800
From: louiskkchan@hotmail.com (Louis)
Subject: variable assignment question. help
Message-Id: <f9151e85.0302242213.2b5076eb@posting.google.com>

hi all,

i used to follow to get cpu status. can i have one 'awk' command to
get all counters? or any script help?

i.e.
my ($user, $nice, $system) = `awk '/$cpu / {print \$2, \$3, \$4}' <
/proc/stat `;

######################################################
# get cpu stat info /proc/stat
my $user = `awk '/$cpu / {print \$2}' < /proc/stat `;
my $nice = `awk '/$cpu / {print \$3}' < /proc/stat `;
my $system = `awk '/$cpu / {print \$4}' < /proc/stat `;
######################################################


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

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


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