[16097] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3509 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 29 11:10:31 2000

Date: Thu, 29 Jun 2000 08:10:19 -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: <962291419-v9-i3509@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 29 Jun 2000     Volume: 9 Number: 3509

Today's topics:
        Newbie: little perl script <sferrandez@wineandco.com>
    Re: Newbie: little perl script <mike.solomon@eps.ltd.uk>
    Re: Newbie: little perl script <sariq@texas.net>
    Re: Newbie: little perl script <sferrandez@wineandco.com>
    Re: Newbie: little perl script <sariq@texas.net>
    Re: Newbie: little perl script (Tad McClellan)
    Re: Newbie: little perl script <sferrandez@wineandco.com>
        Newbie: Windows Explorer-style window posting via cgi (Tony Balazs)
    Re: Newbie: Windows Explorer-style window posting via c <care227@attglobal.net>
        PERL & Informix <bogdan.pitulac@mch20.sbs.de>
        Perl Help Please! <Magic@mattnet.freeserve.co.uk>
    Re: Perl Help Please! <samara_biz@hotmail.com>
    Re: Perl Help Please! (Randal L. Schwartz)
    Re: Redirect <flavell@mail.cern.ch>
        return values without sub <boog@inf.fu-berlin.de>
    Re: return values without sub <aqumsieh@hyperchip.com>
    Re: Script cron problems <at@at.at>
    Re: Start process with Perl/VMS <dan@tuatha.sidhe.org>
    Re: Strange behaviour in upper case conversion (Bill)
    Re: Strange behaviour in upper case conversion (Philip Lees)
    Re: Strange behaviour in upper case conversion <graham.wood@iona.com>
    Re: Strange behaviour in upper case conversion (Bill)
    Re: Strange behaviour in upper case conversion (Philip Lees)
    Re: Strange behaviour in upper case conversion <aqumsieh@hyperchip.com>
    Re: Strange behaviour in upper case conversion <sariq@texas.net>
    Re: Strange behaviour in upper case conversion (Michel Dalle)
    Re: Strange behaviour in upper case conversion (Tad McClellan)
    Re: Strange behaviour in upper case conversion <care227@attglobal.net>
        upload <nesirena@bih.net.ba>
    Re: upload <care227@attglobal.net>
    Re: upload <nomail@nomail.com>
        Using locales with ActiveState 5.6 <thunderbear@bigfoot.com>
        using system() in Perl to execute compiled C++ code dbottoms98@my-deja.com
    Re: using system() in Perl to execute compiled C++ code <care227@attglobal.net>
    Re: while-loop and regex question (Tad McClellan)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 29 Jun 2000 15:43:01 +0200
From: Sebastien FERRANDEZ <sferrandez@wineandco.com>
Subject: Newbie: little perl script
Message-Id: <395B5265.B0AF54F8@wineandco.com>

I have to learn perl today because I'm planning to schedule a cron job
under Solaris in which one of the arguments must look like :
YearMonthDay (ex : today 20000629)

so the command line in the perl file should be :

/usr/local/bin/my_program -log_date 20000629

i.e my function has to concatenate these date fields and give them as an
argument to the command line

My software vendor gave me the following script :

#!/usr/local/bin/perl

$now = time;
@now = localtime($now);
printf "%02d-%02d-%02d\n",$now[5]%100,$now[4],$now[3];

I get 00-05-29 on stdout !!! Today I'd expect 00-06-29 but I'd like to
have 20000629 all concatenated together...
I looked at stuff with localtime() and gmtime() but I have troubles
understanding quickly the way they work ;)
I'm in a hurry to do that little script actually...

Has anyone got an hint ??? thx



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

Date: Thu, 29 Jun 2000 15:02:02 +0100
From: "mike solomon" <mike.solomon@eps.ltd.uk>
Subject: Re: Newbie: little perl script
Message-Id: <8jfkvo$hb8o$1@ID-36965.news.cis.dfn.de>

try

($sec,$min,$hour,$mday,$mon,$year,$wday,$ydat,$isdst)   = localtime();
#add 1 to $mon as $mon has a range of 0-11
$MONTH  =   $mon + 1;
#add 1900 to year
$YEAR = $year + 1900;

printf("%4d%02d%02d\n",${YEAR},${MONTH},${mday});




Sebastien FERRANDEZ <sferrandez@wineandco.com> wrote in message
news:395B5265.B0AF54F8@wineandco.com...
> I have to learn perl today because I'm planning to schedule a cron job
> under Solaris in which one of the arguments must look like :
> YearMonthDay (ex : today 20000629)
>
> so the command line in the perl file should be :
>
> /usr/local/bin/my_program -log_date 20000629
>
> i.e my function has to concatenate these date fields and give them as an
> argument to the command line
>
> My software vendor gave me the following script :
>
> #!/usr/local/bin/perl
>
> $now = time;
> @now = localtime($now);
> printf "%02d-%02d-%02d\n",$now[5]%100,$now[4],$now[3];
>
> I get 00-05-29 on stdout !!! Today I'd expect 00-06-29 but I'd like to
> have 20000629 all concatenated together...
> I looked at stuff with localtime() and gmtime() but I have troubles
> understanding quickly the way they work ;)
> I'm in a hurry to do that little script actually...
>
> Has anyone got an hint ??? thx
>




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

Date: Thu, 29 Jun 2000 09:07:24 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Newbie: little perl script
Message-Id: <395B581C.26B48277@texas.net>

Sebastien FERRANDEZ wrote:
> 
> I have to learn perl today because I'm planning to schedule a cron job
> under Solaris in which one of the arguments must look like :
> YearMonthDay (ex : today 20000629)

perldoc -f localtime

---

#!/usr/bin/perl -w

use strict;

my ($mday,$mon,$year) = (localtime())[3..5];
printf '%4d%02d%02d', $year+1900, $mon+1, $mday;


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

Date: Thu, 29 Jun 2000 16:23:21 +0200
From: Sebastien FERRANDEZ <sferrandez@wineandco.com>
Subject: Re: Newbie: little perl script
Message-Id: <395B5BD9.8131813F@wineandco.com>

Thanks, both of you have nice solutions. Thx.
I get the following message :

localhost% /usr/local/bin/perl -V:d_setlocale
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LC_ALL = (unset),
        LC_COLLATE = "fr",
        LC_CTYPE = "fr",
        LC_MESSAGES = "fr",
        LC_MONETARY = "fr",
        LC_NUMERIC = "C",
        LC_TIME = "us",
        LC_TIME = "us=",
        LC_TIME = "C=",
        LANG = "C"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
d_setlocale='define';

and then I have the string I expected to get. Is it because of LC_ALL being
unset that the message is printed ?



Tom Briles wrote:

> Sebastien FERRANDEZ wrote:
> >
> > I have to learn perl today because I'm planning to schedule a cron job
> > under Solaris in which one of the arguments must look like :
> > YearMonthDay (ex : today 20000629)
>
> perldoc -f localtime
>
> ---
>
> #!/usr/bin/perl -w
>
> use strict;
>
> my ($mday,$mon,$year) = (localtime())[3..5];
> printf '%4d%02d%02d', $year+1900, $mon+1, $mday;



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

Date: Thu, 29 Jun 2000 09:36:13 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Newbie: little perl script
Message-Id: <395B5EDD.4358EDAD@texas.net>

Sebastien FERRANDEZ wrote:
> 
> Thanks, both of you have nice solutions. Thx.
> I get the following message :
> 
> localhost% /usr/local/bin/perl -V:d_setlocale
> perl: warning: Setting locale failed.
> perl: warning: Please check that your locale settings:
>         LC_ALL = (unset),
>         LC_COLLATE = "fr",
>         LC_CTYPE = "fr",
>         LC_MESSAGES = "fr",
>         LC_MONETARY = "fr",
>         LC_NUMERIC = "C",
>         LC_TIME = "us",
>         LC_TIME = "us=",
>         LC_TIME = "C=",
>         LANG = "C"
>     are supported and installed on your system.
> perl: warning: Falling back to the standard locale ("C").
> d_setlocale='define';
> 
> and then I have the string I expected to get. Is it because of LC_ALL being
> unset that the message is printed ?

A couple of suggestions for the future:

1) Use proper Subject lines.

   http://www.perl.com/CPAN-local/authors/Dean_Roehrich/subjects.post

2) Place your responses properly (*after* the quoted message), and only
quote that which is relevant.

That said, Perl's error messages are in the perldiag page of the manual.

perldoc perldiag

You'll probably also want to take a look at:

perldoc perllocale

- Tom


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

Date: Thu, 29 Jun 2000 10:04:29 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Newbie: little perl script
Message-Id: <slrn8lmlrd.3q9.tadmc@magna.metronet.com>

On Thu, 29 Jun 2000 15:43:01 +0200, Sebastien FERRANDEZ <sferrandez@wineandco.com> wrote:

>I have to learn perl today because I'm planning to schedule a cron job
   ^^^^^^^

No you don't. 

You can easily get that done with the Unix 'date' command.


>under Solaris in which one of the arguments must look like :
>YearMonthDay (ex : today 20000629)
>
>so the command line in the perl file should be :
>
>/usr/local/bin/my_program -log_date 20000629


   /usr/local/bin/my_program -log_date `date +%Y%m%d`


Right from the shell, no Perl needed.


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 29 Jun 2000 17:02:39 +0200
From: Sebastien FERRANDEZ <sferrandez@wineandco.com>
Subject: Re: Newbie: little perl script
Message-Id: <395B650F.C8E465B9@wineandco.com>



Tom Briles wrote:

> Sebastien FERRANDEZ wrote:
> 1) Use proper Subject lines.

Sorry, I admit being a bit in a rush with this.
I don't understand why my software vendor made such a freaky script that's not
working.
Everything is OK nevertheless. Thanks to all for your help.




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

Date: Thu, 29 Jun 2000 12:52:14 GMT
From: tbalazs-this-must-go@netcomuk.co.uk (Tony Balazs)
Subject: Newbie: Windows Explorer-style window posting via cgi
Message-Id: <395b4644.16985758@1.0.0.119>

How can I have a button which will open a Windows Explorer-style
window, allowing the user to select a file and then POST it via cgi?

Thanks for any suggestions,

Tony.


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

Date: Thu, 29 Jun 2000 09:43:45 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Newbie: Windows Explorer-style window posting via cgi
Message-Id: <395B5291.ED4DE7AC@attglobal.net>

Tony Balazs wrote:
> 
> How can I have a button which will open a Windows Explorer-style
> window, 

Yes, but that is an HTML question.  Nothing to do with Perl.

> allowing the user to select a file and then POST it via cgi?

Yes as well, but that is a CGI question.  Nothing to do with Perl.
I can send you some lovely COBOL source that will allow file uploads...
Or how about REXX?

Try these groups next time:

comp.infosystems.www.authoring.html 
comp.infosystems.www.authoring.cgi


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

Date: Thu, 29 Jun 2000 15:27:54 +0200
From: Bogdan Pitulac <bogdan.pitulac@mch20.sbs.de>
Subject: PERL & Informix
Message-Id: <395B4ED9.E3099F24@mch20.sbs.de>

Hi everybody,

I have a question:

 How can I use sql-Statemens in a PERL (V5.00) -Script to get some data
out a Informix (V7.30) database? Or where can I read something about
these things?

Thanks very much...



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

Date: Thu, 29 Jun 2000 12:41:41 +0100
From: Magic <Magic@mattnet.freeserve.co.uk>
Subject: Perl Help Please!
Message-Id: <hbdmlso660dmvftuol06t8bbtb0ns5jcb7@4ax.com>

Hi all,

	I need a simple script which will let me do this:

If I call it using
"myscript.cgi?WORD=CHEESE&PAGE=page3.html"

then it will send page3.html to the browser replacing all occurrences
of "!THE_WORD!" with "CHEESE".

Does anyone have a script like that which I could look at?

Thanks.


Magic        ==|:o)
-- 
Location : Portsmouth, England, UK
Homepage : http://www.mattnet.freeserve.co.uk
EMail : mailto:Magic@mattnet.freeserve.co.uk


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

Date: Thu, 29 Jun 2000 08:08:28 -0400
From: "Alex T." <samara_biz@hotmail.com>
Subject: Re: Perl Help Please!
Message-Id: <395B3C3C.590CA726@hotmail.com>

I think I saw something like that on www.perlscripters.com or at one of
the links from that web-site.

Alex

Magic wrote:

> Hi all,
>
>         I need a simple script which will let me do this:
>
> If I call it using
> "myscript.cgi?WORD=CHEESE&PAGE=page3.html"
>
> then it will send page3.html to the browser replacing all occurrences
> of "!THE_WORD!" with "CHEESE".
>
> Does anyone have a script like that which I could look at?
>
> Thanks.
>
> Magic        ==|:o)
> --
> Location : Portsmouth, England, UK
> Homepage : http://www.mattnet.freeserve.co.uk
> EMail : mailto:Magic@mattnet.freeserve.co.uk



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

Date: 29 Jun 2000 07:09:09 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl Help Please!
Message-Id: <m1aeg4o9yy.fsf@halfdome.holdit.com>

>>>>> "Magic" == Magic  <Magic@mattnet.freeserve.co.uk> writes:

Magic> If I call it using
Magic> "myscript.cgi?WORD=CHEESE&PAGE=page3.html"

Magic> then it will send page3.html to the browser replacing all occurrences
Magic> of "!THE_WORD!" with "CHEESE".

Magic> Does anyone have a script like that which I could look at?

Just be very careful that the script doesn't permit

        myscript?WORD=CHEESE&PAGE=../../../../etc/passwd

Amazing how many of them do. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 29 Jun 2000 11:52:04 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Redirect
Message-Id: <Pine.GHP.4.21.0006291145020.5746-100000@hpplus03.cern.ch>

On Thu, 29 Jun 2000, Jim Kauzlarich confirmed the usual theory about
upside-down quoters by blurting out:

> print "Location: ../index2.html?wisdom=$line\n\n";

This is not one of the valid forms of Location CGI response codified
in the CGI interworking specifications.  In other words, it's an
invalid CGI response.

> This is an example of the (entire) output it might generate:
> 
> Location:
> ../index2.html?wisdom=$%22640K+ought+to+be+enough+for+anybody.%22+-+Bill+Gat
> es,+1981

This is also not one of the forms of Location HTTP header codified
in the HTTP specifications.  In other words, it'a an invalid HTTP
response. 

> Hope this helps!

Might very well do, because anyone knows that the advice offered by
upside-down quoters is probably wrong.  But I'd prefer a more direct
way of communicating the answer than this.  See the CGI specification,
and the relevant HTTP RFC; or start from the appropriate FAQs.

This also isn't a perl language issue.  f'ups redirected.



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

Date: Thu, 29 Jun 2000 16:28:45 +0200
From: Hinrich Boog <boog@inf.fu-berlin.de>
Subject: return values without sub
Message-Id: <395B5D1D.6DEDAA44@inf.fu-berlin.de>

Hi there,

I've got a short question on returning values:

I am calling a perl-script from a cshell-script.

set var= "`scriptname arguments`"

The question is: How do I define the value that is returned by the
perl-script? If I use return, the compiler tells me, that I can't use
return outside a subroutine. I just want to reuse a value, that I
calculated in my script...

Thanks.
Hinrich




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

Date: Thu, 29 Jun 2000 14:31:29 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: return values without sub
Message-Id: <7a4s6c7e4d.fsf@merlin.hyperchip.com>


Hinrich Boog <boog@inf.fu-berlin.de> writes:

> The question is: How do I define the value that is returned by the
> perl-script? 

use:

	exit $return_code;

--Ala


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

Date: Thu, 29 Jun 2000 13:54:13 +0100
From: jr <at@at.at>
To: gulgan@my-deja.com
Subject: Re: Script cron problems
Message-Id: <395B46F5.B8F4CBB4@at.at>

 .. and if this is not the problem I would guess some environment variable
(especially PATH) has a value different from when you run it from the command
line.

jr

Todd Anderson wrote:

> gulgan@my-deja.com wrote:
>
> > I have croned a script as root (let's not get into the discussion as to
> > why it's a long sotry) and it doesn't seem to be running with root
> > permissions.  It runs fine at command line but it fails when trying to
> > run via cron.  Any ideas?
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
>
> Cron doesn't see relative paths. Convert all your global varibles to
> absolute paths.
> ie: $my_script = "my_script.cgi";
>   ... to... $my_script = "/home/my/thingybob/my_script.cgi";



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

Date: Thu, 29 Jun 2000 03:20:26 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Start process with Perl/VMS
Message-Id: <_fz65.18194$Zg4.50461@news1.rdc1.ct.home.com>

Pierre Coucoureux <coucoureux.p@fr.ibm.com> wrote:
> Does anyone know how to start a process asynchronously with Perl on VMS
> and how to get the returned status code of this new process?

> I want to replace the famous sequence fork + exec and waitpid that
> workss on Unix platform.

Then try magic open:

 open(FOO, "|some_exe_name");

which'll spawn off the process just like on unix. When you close the
filehandle the exit code of the program will be in $?. (If "use vmsish" is
in effect it'll be the full 32-bit VMS status, otherwise it's a unixy code
that's generally useless)

					Dan


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

Date: Thu, 29 Jun 2000 10:34:18 GMT
From: wfeidt@cpcug.org (Bill)
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <8F6249DCCwfeidthiscom@207.126.101.97>

pjlees@ics.forthcomingevents.gr (Philip Lees) wrote in
<395b077a.69690459@news.grnet.gr>: 

>Now suppose I want to make just the first letter upper case and leave
>the rest as it is. From what I've read in perlop and perlre, the ^
>operator should match just the first character of the string. So
>
>($name = $name) =~ tr/^[a-z]/[A-Z]/;
>
>should do the job. Right? Wrong. What it does is convert the whole
>string to upper case _and_ bump each character up by one ASCII code,
>thus 'foo' becomes 'GPP', etc. Can anyone explain this?
>
>My aim is to find something that formats names in a consistent way
>from user input, so that
>
>fiRsTnAmE LaStNaME would become
>
>Firstname LASTNAME.

Have a look at the ucfirst function:

  perldoc -f ucfirst

Also, you'll want to use the "=" operator rather than the
"=~" operator when making the assignment.  The solution to
the problem does not involve regular expressions.

In addition, the "Programming Perl" book suggests:

  "To force initial caps, and everything else lowercase,
   use:
  
      ucfirst lc $word"

so, for example: $name = ucfirst lc $name;

HTH,

Bill Feidt
wfeidt@cpcug.org


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

Date: Thu, 29 Jun 2000 10:44:58 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <395b27a7.77927954@news.grnet.gr>

On Thu, 29 Jun 2000 10:34:18 GMT, wfeidt@cpcug.org (Bill) wrote:

>Have a look at the ucfirst function:
>
>  perldoc -f ucfirst
>
>Also, you'll want to use the "=" operator rather than the
>"=~" operator when making the assignment.  The solution to
>the problem does not involve regular expressions.
>
>In addition, the "Programming Perl" book suggests:
>
>  "To force initial caps, and everything else lowercase,
>   use:
>  
>      ucfirst lc $word"

Thanks for answering, Bill, but as I said in my original post, lc, uc,
etc. don't work with the Greek character set - i.e. they leave the
string as it was.

I tried "=" in place of "=~", but that just returned a zero.

Phil
--
Philip Lees
ICS-FORTH, Heraklion, Crete, Greece
Ignore coming events if you wish to send me e-mail
'The aim of high technology should be to simplify, not complicate' - Hans Christian von Baeyer


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

Date: Thu, 29 Jun 2000 11:54:17 +0100
From: "Graham Wood" <graham.wood@iona.com>
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <8jfa6q$bb3$1@bvweb.iona.com>

I also witnessed but can't explain the weird behaviour. Nor could I get a
1-liner to work.  Here's 2 lines that will convert your first character to
the upper case using tr.

($first=substr($name,0,1))=~ tr/[a-z]/[A-Z]/;
$name=join('', $first ,substr($name,1));

Graham Wood

Philip Lees <pjlees@ics.forthcomingevents.gr> wrote in message
news:395b077a.69690459@news.grnet.gr...
> Hi. I'm trying to learn something about regex use in Perl and I came
> across a curious problem. I started with something simple:
>
> ($name = $name) =~ tr/[a-z]/[A-Z]/;
>
> This converts $name to upper case. Fine.
>
> Now suppose I want to make just the first letter upper case and leave
> the rest as it is. From what I've read in perlop and perlre, the ^
> operator should match just the first character of the string. So
>
> ($name = $name) =~ tr/^[a-z]/[A-Z]/;
>
> should do the job. Right? Wrong. What it does is convert the whole
> string to upper case _and_ bump each character up by one ASCII code,
> thus 'foo' becomes 'GPP', etc. Can anyone explain this?
>
> My aim is to find something that formats names in a consistent way
> from user input, so that
>
> fiRsTnAmE LaStNaME would become
>
> Firstname LASTNAME.
>
> The reason I'm doing it this way is because I work in a bilingual
> environment and uc() and lc() don't work for the Greek character set,
> (e.g. join( '',uc( substr( $first,0,1)), lc(substr($first,1))  works
> in English, but not in Greek), whereas my first example works in both
> languages (if I add the Greek character ranges, of course).
>
> Incidentally, my second attempt above, when modified to include Greek,
> does the same as before, except that some Greek letters are bumped up
> by one and others by two ASCII codes. Bizarre!
>
> I'm sure this will seem quite simple to you gurus. All help
> appreciated.
>
> Phil
> --
> Philip Lees
> ICS-FORTH, Heraklion, Crete, Greece
> Ignore coming events if you wish to send me e-mail
> 'The aim of high technology should be to simplify, not complicate' - Hans
Christian von Baeyer




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

Date: 29 Jun 2000 11:43:33 GMT
From: wfeidt@cpcug.org (Bill)
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <8F6243F7Cwfeidthiscom@205.139.105.25>

>Thanks for answering, Bill, but as I said in my original post, lc, uc,
>etc. don't work with the Greek character set - i.e. they leave the
>string as it was.
>
>I tried "=" in place of "=~", but that just returned a zero.

Apologies, Phil.  I read your post too quickly.  Good luck with
the problem.

Bill Feidt
wfeidt@cpcug.org


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

Date: Thu, 29 Jun 2000 12:53:01 GMT
From: pjlees@ics.forthcomingevents.gr (Philip Lees)
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <395b454d.85517067@news.grnet.gr>

On Thu, 29 Jun 2000 11:54:17 +0100, "Graham Wood"
<graham.wood@iona.com> wrote:

>I also witnessed but can't explain the weird behaviour. Nor could I get a
>1-liner to work.  Here's 2 lines that will convert your first character to
>the upper case using tr.
>
>($first=substr($name,0,1))=~ tr/[a-z]/[A-Z]/;
>$name=join('', $first ,substr($name,1));

Thanks for the help, Graham. With a little more I have what I want,
working with strict, too!

(my $first = substr( $name, 0, 1 ))  =~tr/[a-z]/[A-Z]/;
(my $rest  = substr( $name, 1 ))    =~ tr/[A-Z]/[a-z]/;
$name = join('', $first , $rest );

When I add the Greek character ranges everything is fine in both
languages.

I'm still curious about the behaviour of my original attempt, though.

Phil
--
Philip Lees
ICS-FORTH, Heraklion, Crete, Greece
Ignore coming events if you wish to send me e-mail
'The aim of high technology should be to simplify, not complicate' - Hans Christian von Baeyer


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

Date: Thu, 29 Jun 2000 13:30:28 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <7an1k4d37u.fsf@merlin.hyperchip.com>


pjlees@ics.forthcomingevents.gr (Philip Lees) writes:

> Hi. I'm trying to learn something about regex use in Perl and I came
> across a curious problem. I started with something simple:
> 
> ($name = $name) =~ tr/[a-z]/[A-Z]/;

Just for the record: The above does not involve regular expressions.

There is a difference between regular expressions (m// and s///) and
translation (tr/// aka transliteration).

What you have above is translation which simply changes each character
in your string that matches any character in the left hand side of your
tr/// statement with the corresponding character in the right hand
side. For example:

	tr/a/b/;

will change all a's to b's.

	tr/a /ty/;

will change all a's to t's and all spaces to y's.

> This converts $name to upper case. Fine.
> 
> Now suppose I want to make just the first letter upper case and leave
> the rest as it is. From what I've read in perlop and perlre, the ^
> operator should match just the first character of the string. So
> 
> ($name = $name) =~ tr/^[a-z]/[A-Z]/;
> 
> should do the job. Right? Wrong. What it does is convert the whole
> string to upper case _and_ bump each character up by one ASCII code,
> thus 'foo' becomes 'GPP', etc. Can anyone explain this?

Read the above and it should be clear. The ^ gets converted to a [, the
[ to an A, the a to a B, the b to a C, etc ... 

You also don't need the square brackets. You are confusing tr/// with
s///.  Read perlop for more info on tr/// and s///.

--Ala


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

Date: Thu, 29 Jun 2000 08:50:31 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <395B5427.ABD2D1D8@texas.net>

Philip Lees wrote:
> 
> Hi. I'm trying to learn something about regex use in Perl and I came
> across a curious problem. I started with something simple:
> 
> ($name = $name) =~ tr/[a-z]/[A-Z]/;

Errr, you know that this is equivalent to:

$name =~ tr/a-z/A-Z/;

right?  Because you read the documentation in the perlop page of the
manual for the bind operator, tr///, and s///, right?

<Snipped the evidence that you have *not* read the proper documentation,
but would rather have someone else read it for you, and regurgitate.>

Whoops...
 
> I'm sure this will seem quite simple to you gurus.

It's quite simple for anyone who RTFM.

- Tom


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

Date: Thu, 29 Jun 2000 14:00:41 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <8jfkvf$j0t$1@news.mch.sbs.de>

In article <395b454d.85517067@news.grnet.gr>, pjlees@ics.forthcomingevents.gr (Philip Lees) wrote:
[snip]
>I'm still curious about the behaviour of my original attempt, though.
>
>Phil

tr/^[a-z]/[A-Z]/ would translate ^ to [, [ to A, a to B, etc.

So 'foo' will indeed become 'GPP' :)

HTH,

Michel.


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

Date: Thu, 29 Jun 2000 09:05:37 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <slrn8lmid1.2uo.tadmc@magna.metronet.com>

On Thu, 29 Jun 2000 08:49:27 GMT, Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>Hi. I'm trying to learn something about regex use in Perl and I came
>across a curious problem. I started with something simple:
>
>($name = $name) =~ tr/[a-z]/[A-Z]/;


That looks like Cargo Cult programming to me...


>This converts $name to upper case. Fine.


and so does

   $name =~ tr/[a-z]/[A-Z]/;

and so does

   $name =~ tr/a-z/A-Z/;

replacing '[' with '[' and ']' with ']' doesn't seem to
be accomplishing much  :-)



Have you read the docs for the operator that you are using?

If not, then how can you know what behavior to expect from it?

   perldoc perlop


This bit seems particularly germane to your situation:

   "Note also that the whole range idea is rather unportable between
    character sets"


>Now suppose I want to make just the first letter upper case and leave
>the rest as it is. From what I've read in perlop and perlre, the ^
                                                      ^^^^^^


perlre has nothing to do with tr///, because tr/// does not
use regular expressions!

You would already know this if you read the docs for the
operator that you are using...


>operator should match just the first character of the string. So
>
>($name = $name) =~ tr/^[a-z]/[A-Z]/;
>
>should do the job. Right? Wrong. What it does is convert the whole
>string to upper case _and_ bump each character up by one ASCII code,
>thus 'foo' becomes 'GPP', etc. Can anyone explain this?


That is what it is supposed to do.

tr/// does not use regular expressions!

You have asked to translate:

   ^  ->  [

   [  ->  A

   a  ->  B

   ...


>My aim is to find something that formats names in a consistent way
>from user input, so that
>
>fiRsTnAmE LaStNaME would become
>
>Firstname LASTNAME.


Perl FAQ, part 4:

   "How do I capitalize all the words on one line?"


>The reason I'm doing it this way is because I work in a bilingual
>environment


Do you have your locale setup correctly?

   perldoc perllocale


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 29 Jun 2000 10:30:45 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Strange behaviour in upper case conversion
Message-Id: <395B5D95.30A2F475@attglobal.net>

Philip Lees wrote:
> 
> Hi. I'm trying to learn something about regex use in Perl and I came
> across a curious problem. I started with something simple:
> 
> ($name = $name) =~ tr/[a-z]/[A-Z]/;

Why are you using this ($name = $name) notation?  You aren't making a
modification of the lvalue, so its really not needed.  

$name =~ tr/[a-z]/[A-Z]/; # will work just as well. 

> 
> This converts $name to upper case. Fine.
> 
> Now suppose I want to make just the first letter upper case and leave
> the rest as it is. From what I've read in perlop and perlre, the ^
> operator should match just the first character of the string. So

Wrong.  The ^ matches the start of a line/string, which is really
_before_ the first position.  So this will match only at the start 
of a line/string.  That is, for a normal regex.  I don't see anything 
in perlre or perlop to specify that when using the tr/// operator ^ 
has a different meaning. 

> 
> ($name = $name) =~ tr/^[a-z]/[A-Z]/;
> 

But, from the perlop page we see that tr "Transliterates all 
occurrences of the characters found in the search list with 
the corresponding character in the replacement list", so you 
may want to consider a different beast to change the case on 
just the first letter of a word.  

So maybe you should dump the transliteration and go with a simple
search/replace when you only want to change the first letter.

(disclaimer:  I suck with regular expressions  =)

$name =~ s/^[a-z]/\u$1/  #should match start of string and ucase the 
                         #first char.  

$name =~ s/\b[a-z]/\u$1/ #using word boundries in case the pattern 
                           #doesn't need to match start of string.


And, speaking of Greek charachter sets, have you read the locale 
documentation?

http://www.perl.com/pub/doc/manual/html/pod/perllocale.html

Might make your life a bit easier.


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

Date: Thu, 29 Jun 2000 15:48:04 +0200
From: "Nesiren Armin" <nesirena@bih.net.ba>
Subject: upload
Message-Id: <8jfk51$11j1@ns4.bih.net.ba>

Hi !

Somebody know how to upload file from web site to server ... whit cgi-perl
script... thanks!




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

Date: Thu, 29 Jun 2000 10:59:57 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: upload
Message-Id: <395B646D.CF3DE4FB@attglobal.net>

Nesiren Armin wrote:
> 
> Hi !
> 
> Somebody know how to upload file from web site to server ... whit cgi-perl
> script... thanks!

I do!  I bet lots of others do too!! I bet someone even wrote 
some documentation on how to do it.  (hint)


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

Date: Thu, 29 Jun 2000 08:47:35 -0400
From: "Jonah" <nomail@nomail.com>
Subject: Re: upload
Message-Id: <8jfnnm$88s$1@onlink3.onlink.net>


Nesiren Armin <nesirena@bih.net.ba> wrote in message
news:8jfk51$11j1@ns4.bih.net.ba...
> Hi !
>
> Somebody know how to upload file from web site to server ... whit cgi-perl
> script... thanks!
>
>

I sure do!




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

Date: Thu, 29 Jun 2000 15:43:51 +0200
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Using locales with ActiveState 5.6
Message-Id: <395B5297.E614561E@bigfoot.com>


I would like to uppercase German text preferrably using
locales under NT 4.0 with the ActiveState 5.6 port of Perl.  

The machine in question has English and Danish input locales
installed.

Is it at all possible to use locales with Perl to do this,
and -- if so -- how?

Currntly I've just settled with a large "tr///" line
instead.

Thanks in advance,
-- 
  Thorbjørn Ravn Andersen         "...plus...Tubular Bells!"
  http://bigfoot.com/~thunderbear


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

Date: Thu, 29 Jun 2000 12:17:15 GMT
From: dbottoms98@my-deja.com
Subject: using system() in Perl to execute compiled C++ code
Message-Id: <8jfenu$4h9$1@nnrp1.deja.com>

Hello,

 I use the system() function in Perl to execute compiled C++ (binary).
If I run the Perl script from the shell the program works fine and the
system function works, returning a value of 139.  However as soon as I
run it via the web (running apache), the system function does not
execute the C++ binary and the system returned value is 256.  The man
pages explain that you need to divide this number by 256 to find its
real meaning...and I think I found somewhere that the number 1 (256/256)
means the operation is not permitted. Has anyone heard of this problem??
where the same Perl script can be run from the same directory; one from
the shell and the other from the web and get such different results???
any assistance would be great on how to get around this "operation not
permitted" problem!

 Thank you.

 David Bottoms


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 29 Jun 2000 09:54:03 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: using system() in Perl to execute compiled C++ code
Message-Id: <395B54FB.EC22DD60@attglobal.net>

dbottoms98@my-deja.com wrote:
> 
> Hello,
> 
> Has anyone heard of this problem??
> where the same Perl script can be run from the same directory; one from
> the shell and the other from the web and get such different results???
> any assistance would be great on how to get around this "operation not
> permitted" problem!
> 

I bet a quick search of this group on Deja would have revealed that 
not only you have seen this problem.  In fact, It is so common it is 
in many popular FAQ's.  You could have found out even more by searching
the archive of a group where this question is on topic.  Specifically,
comp.infosystems.www.authoring.cgi

Long story short, make sure the userid that owns the webserver process
has sufficient permission to execute the program you want to fork to. 

(Notice that this has nothing to do with Perl, could you?)


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

Date: Thu, 29 Jun 2000 08:17:32 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: while-loop and regex question
Message-Id: <slrn8lmfis.2uo.tadmc@magna.metronet.com>

On Thu, 29 Jun 2000 10:30:33 +0200, Hubert Ming <hubert.ming@iggi.lu.ch> wrote:
>dear perl-gurus,
>i don't understand how this function works. can you please give me further
>explanation:
>
>my ($res) = "";
>while ($_[0] =~ /(.{1,45})/gs)


Matches 1-45 of any character (including newlines), saves
the matched characters in $1.


>         {
>         $res .= substr(pack('u', $1), 1);
>         chop($res);
>         }


Packs the 1-45 characters into a uuencoded string and 
concatenates all but the first character onto $res, then
removes the last character.


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

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


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