[25722] in Perl-Users-Digest
Perl-Users Digest, Issue: 7962 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 11 09:05:58 2005
Date: Mon, 11 Apr 2005 06:05:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 11 Apr 2005 Volume: 10 Number: 7962
Today's topics:
Re: Basic Regular Expressions question... <bart.lateur@pandora.be>
Re: Basic Regular Expressions question... (Anno Siegel)
get mod_perl max memory usage <alexj@floor.ch>
Re: How to create an empty file? <tintin@invalid.invalid>
Re: How to create an empty file? (Anno Siegel)
Re: How to create an empty file? (Heinrich Mislik)
Re: if(wantarray){...}else{...} <burlo.stumproot@gmail.com>
Re: if(wantarray){...}else{...} (Anno Siegel)
Re: if(wantarray){...}else{...} <1usa@llenroc.ude.invalid>
Re: if(wantarray){...}else{...} (Anno Siegel)
Re: if(wantarray){...}else{...} <1usa@llenroc.ude.invalid>
Re: IIS calling cscript.exe from cgi permission denied <1usa@llenroc.ude.invalid>
Simple Encryption Script <hackeras@gmail.com>
Re: Simple Encryption Script <josef.moellers@fujitsu-siemens.com>
Re: Simple Encryption Script <someone@example.com>
Re: Simple Encryption Script (Anno Siegel)
Re: Simple Encryption Script <hackeras@gmail.com>
Re: Simple Encryption Script <hackeras@gmail.com>
Re: Simple Encryption Script <someone@example.com>
Re: Simple Encryption Script <someone@example.com>
Re: Simple Encryption Script <someone@example.com>
Re: Simple Encryption Script (Anno Siegel)
Re: Simple Encryption Script <tadmc@augustmail.com>
Re: UTF-8 in regexp with 5.8.1 <flavell@ph.gla.ac.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Apr 2005 08:06:44 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Basic Regular Expressions question...
Message-Id: <7tbk51traapj3be260jr46khfb6m4ocpjv@4ax.com>
Anno Siegel wrote:
>You're right, though I wouldn't bother with storing the length of
>anything. Working backwards runs smoother:
>
> my $i = length $thisPage;
> substr( $thisPage, $i, length $find) = $replace while
> ( $i = rindex $thisPage, $find, $i) >= 0;
>
>That way only the unchanged part of the string is ever searched.
I'm sure you're aware that the behaviour of this version is not the same
as the original one for overlapping matches. Try replacing "papa" in
"papapaya", for example.
--
Bart.
------------------------------
Date: 11 Apr 2005 08:54:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Basic Regular Expressions question...
Message-Id: <d3ddvv$s16$1@mamenchi.zrz.TU-Berlin.DE>
Bart Lateur <bart.lateur@pandora.be> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> >You're right, though I wouldn't bother with storing the length of
> >anything. Working backwards runs smoother:
> >
> > my $i = length $thisPage;
> > substr( $thisPage, $i, length $find) = $replace while
> > ( $i = rindex $thisPage, $find, $i) >= 0;
> >
> >That way only the unchanged part of the string is ever searched.
>
> I'm sure you're aware that the behaviour of this version is not the same
> as the original one for overlapping matches. Try replacing "papa" in
> "papapaya", for example.
Frankly, no, I didn't notice. Thanks for pointing it out.
Anno
------------------------------
Date: Mon, 11 Apr 2005 11:58:38 +0200
From: Alexandre Jaquet <alexj@floor.ch>
Subject: get mod_perl max memory usage
Message-Id: <d3dhob$qil$1@news.hispeed.ch>
Hi,
I'm looking for the to get the maximum memory usage autorized for
mod_perl is there any test script I can run
thanks in advance
Alexandre Jaquet
------------------------------
Date: Mon, 11 Apr 2005 21:50:46 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: How to create an empty file?
Message-Id: <_Lr6e.17740$1S4.1775460@news.xtra.co.nz>
"bill" <please_post@nomail.edu> wrote in message
news:d3a48u$o1g$1@reader1.panix.com...
>
>
>
> What's the best way to create an empty file? I mean is there
> something less circuitous than
>
> {
> my $inane;
> open my $inane, '>', $empty and close $inane
> or die "Failed to create $empty: $!\n";
> }
>
> and that does not use system(), as in
>
> system('touch', $empty);
Your two examples do different things (sometimes). Which is it to be?
------------------------------
Date: 11 Apr 2005 10:45:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to create an empty file?
Message-Id: <d3dkh6$3iq$2@mamenchi.zrz.TU-Berlin.DE>
Tintin <tintin@invalid.invalid> wrote in comp.lang.perl.misc:
>
> "bill" <please_post@nomail.edu> wrote in message
> news:d3a48u$o1g$1@reader1.panix.com...
> >
> >
> >
> > What's the best way to create an empty file? I mean is there
> > something less circuitous than
> >
> > {
> > my $inane;
> > open my $inane, '>', $empty and close $inane
> > or die "Failed to create $empty: $!\n";
> > }
> >
> > and that does not use system(), as in
> >
> > system('touch', $empty);
>
> Your two examples do different things (sometimes). Which is it to be?
If the objective is to create an *empty* file, the "touch" example is
bogus anyway.
Anno
------------------------------
Date: 11 Apr 2005 12:25:41 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: How to create an empty file?
Message-Id: <425a6cc0$0$12384$3b214f66@usenet.univie.ac.at>
In article <d3a48u$o1g$1@reader1.panix.com>, please_post@nomail.edu says...
>What's the best way to create an empty file? I mean is there
>something less circuitous than
>
>{
> my $inane;
> open my $inane, '>', $empty and close $inane
> or die "Failed to create $empty: $!\n";
>}
>
use File::Slurp;
write_file('empty');
Cheers
Heinrich
--
Heinrich Mislik
Zentraler Informatikdienst der Universitaet Wien
A-1010 Wien, Universitaetsstrasse 7
Tel.: (+43 1) 4277-14056, Fax: (+43 1) 4277-9140
------------------------------
Date: 11 Apr 2005 01:24:51 -0700
From: "Stumproot" <burlo.stumproot@gmail.com>
Subject: Re: if(wantarray){...}else{...}
Message-Id: <1113207891.290302.69500@f14g2000cwb.googlegroups.com>
Tad McClellan wrote:
> Stumproot <burlo.stumproot@gmail.com> wrote:
>
> > Posted from/using google news.
> What is the relevance of including that?
Somtimes google does funny things with formatting of replies and I
thought it would be nice to warn people I'm using a less than ideal way
to post.
<snip code and commets re wantarray>
> Context is "see through". In the code below, A_Funktion() sees
> whatever context fun1() got called in.
>
>
> -----------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my $scalar = fun1();
> my($list) = fun1();
> my($a1,$a2);
>
> sub fun1 {
> # lots going on...
> return A_Funktion($a1,$a2);
> }
>
> sub A_Funktion {
> if(wantarray) {
> warn "A_Funktion() in list context\n"
> } else {
> warn "A_Funktion() in scalar context\n"
> }
> }
> -----------------------------
This I did not know, very handy.
Thanks.
------------------------------
Date: 11 Apr 2005 09:38:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: if(wantarray){...}else{...}
Message-Id: <d3dgji$6j$1@mamenchi.zrz.TU-Berlin.DE>
Stumproot <burlo.stumproot@gmail.com> wrote in comp.lang.perl.misc:
> A. Sinan Unur wrote:
> > "Stumproot" <burlo.stumproot@gmail.com> wrote in
[...]
> But for future use I'll remember this snippet, using scalar on a
> function never occured to me even though I know it works.
>
> > wantarray ? A_Funktion(@_) : scalar A_Funktion(@_);
This is a no-op. In array context it calls A_Function in array context,
in scalar context it calls it in scalar context. It would do the same
without explicit "scalar" in the last operand. I'm not sure why Sinan
mentioned it in his posting, he never used it anywhere.
Anno
------------------------------
Date: Mon, 11 Apr 2005 10:57:50 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: if(wantarray){...}else{...}
Message-Id: <Xns963546C5A96F0asu1cornelledu@127.0.0.1>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
news:d3dgji$6j$1@mamenchi.zrz.TU-Berlin.DE:
> Stumproot <burlo.stumproot@gmail.com> wrote in comp.lang.perl.misc:
>> A. Sinan Unur wrote:
>> > "Stumproot" <burlo.stumproot@gmail.com> wrote in
>
> [...]
>
>> But for future use I'll remember this snippet, using scalar on a
>> function never occured to me even though I know it works.
>>
>> > wantarray ? A_Funktion(@_) : scalar A_Funktion(@_);
>
> This is a no-op. In array context it calls A_Function in array
> context, in scalar context it calls it in scalar context. It would do
> the same without explicit "scalar" in the last operand. I'm not sure
> why Sinan mentioned it in his posting, he never used it anywhere.
I was assuming that of A_Funktion_Caller is called in scalar context, it
needs to call A_Funktion in scalar context for some *intermediate*
calculations. The fact that I did not put anything of substance in the
body of A_Funktion_Caller and typos I corrected in a later message
obscured that assumption.
Sorry.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 11 Apr 2005 11:07:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: if(wantarray){...}else{...}
Message-Id: <d3dlok$3iq$3@mamenchi.zrz.TU-Berlin.DE>
A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
> news:d3dgji$6j$1@mamenchi.zrz.TU-Berlin.DE:
>
> > Stumproot <burlo.stumproot@gmail.com> wrote in comp.lang.perl.misc:
> >> A. Sinan Unur wrote:
> >> > "Stumproot" <burlo.stumproot@gmail.com> wrote in
> >
> > [...]
> >
> >> But for future use I'll remember this snippet, using scalar on a
> >> function never occured to me even though I know it works.
> >>
> >> > wantarray ? A_Funktion(@_) : scalar A_Funktion(@_);
> >
> > This is a no-op. In array context it calls A_Function in array
> > context, in scalar context it calls it in scalar context. It would do
> > the same without explicit "scalar" in the last operand. I'm not sure
> > why Sinan mentioned it in his posting, he never used it anywhere.
>
> I was assuming that of A_Funktion_Caller is called in scalar context, it
> needs to call A_Funktion in scalar context for some *intermediate*
> calculations. The fact that I did not put anything of substance in the
> body of A_Funktion_Caller and typos I corrected in a later message
> obscured that assumption.
I still don't see how
wantarray ? A_Funktion(@_) : scalar A_Funktion(@_);
would ever do anything different from just
A_Funktion(@_);
Anno
------------------------------
Date: Mon, 11 Apr 2005 13:03:01 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: if(wantarray){...}else{...}
Message-Id: <Xns96355BFF26A78asu1cornelledu@127.0.0.1>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
news:d3dlok$3iq$3@mamenchi.zrz.TU-Berlin.DE:
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote in comp.lang.perl.misc:
>> I was assuming that of A_Funktion_Caller is called in scalar context,
>> it needs to call A_Funktion in scalar context for some *intermediate*
>> calculations.
...
> I still don't see how
>
> wantarray ? A_Funktion(@_) : scalar A_Funktion(@_);
>
> would ever do anything different from just
>
> A_Funktion(@_);
Of course it wouldn't :)
To tell you the truth, this was the first time that I ever used
wantarray, and I was really straining to find a possible justification
for using wantarray. In the process, I might have overdone it.
The following is another convoluted example. If I am still failing, I'll
just go learn APL or something :)
#! /usr/bin/perl
my @r = call_letters();
my $r = call_letters();
print "@r\n$r\n";
sub call_letters {
wantarray
? select_letters()
: length(scalar select_letters());
}
sub select_letters {
my @letters;
for my $letter ( 'A' .. 'Z' ) {
if(rand(1) < 0.5) {
push @letters, $letter;
}
}
wantarray ? @letters : join('', @letters);
}
__END__
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Mon, 11 Apr 2005 11:01:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: IIS calling cscript.exe from cgi permission denied - WMI access
Message-Id: <Xns96354775BAC46asu1cornelledu@127.0.0.1>
"J M" <JM@jm.biz> wrote in
news:8Pm6e.448$zq4.169@newssvr11.news.prodigy.com:
> I have a perl cgi script on Windows 2003 server with IIS 6.0 that is
> calling prnport.vbs, prnmgr.vbs (supplied by microsoft that creates
> printer port and print queue on server) however IIS returns "cscript
> ... permission denied" error even after adding IUSR_<SERVER> user id
> to administrator list. It appears that error code indicates that WMI
> root object is not accessable by IUSR account. Any suggestions?
>
> I am simply calling vbs script using back tick in perl
> `<PATH>:\\cscript <PATH>:\\prnport.vbs options`
This is a web server configuration issue. Please ask in a newsgroup
appropriate to the platform you are using.
As an aside, please don't give administrator privilidge to the account
your web server is running under. For your own good.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Mon, 11 Apr 2005 08:27:10 +0000 (UTC)
From: Nikos <hackeras@gmail.com>
Subject: Simple Encryption Script
Message-Id: <Xns96357481E5511hackerasgmailcom@194.177.210.210>
#!/usr/bin/perl
print "Enter text to be encrypted: ";
$toBeEncrypted = <>;
@letters = split //, $toBeEncrypted; # load the user input to an array
letter by letter
foreach (@letters) {
$letters[$_] = chr($letters[$_] + 1); # take each letter and convert it
to the next one alphabetically
}
print "Encrypted text now is: @letters\n";
I have made the ebove, but somehow aint working.
--
Just because I didnt doesnt mean I dont want to.
Just because I wouldnt doesnt mean I cant.
------------------------------
Date: Mon, 11 Apr 2005 10:36:57 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Simple Encryption Script
Message-Id: <d3dd5c$3qb$1@nntp.fujitsu-siemens.com>
Nikos wrote:
> #!/usr/bin/perl
>=20
> print "Enter text to be encrypted: ";
> $toBeEncrypted =3D <>;
>=20
> @letters =3D split //, $toBeEncrypted; # load the user input to an arra=
y=20
> letter by letter
>=20
> foreach (@letters) {
> $letters[$_] =3D chr($letters[$_] + 1); # take each letter and conve=
rt it=20
> to the next one alphabetically
> }
>=20
> print "Encrypted text now is: @letters\n";
>=20
>=20
> I have made the ebove, but somehow aint working.
$_ is an alias for the currently selected element of @letters. Also, if=20
$_ contains a letter, it contains a letter, not a number, so=20
incrementing won't work:
$_ =3D chr(ord($_) + 1);
If you've added "use warnings; use strict;", perl would've told you that
Enter text to be encrypted: Hello
Argument "H" isn't numeric in array element at enc.pl line 12, <> line 1.=
Argument "e" isn't numeric in array element at enc.pl line 12, <> line 1.=
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.=
Argument "l" isn't numeric in array element at enc.pl line 12, <> line 1.=
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.=
Argument "l" isn't numeric in array element at enc.pl line 12, <> line 1.=
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.=
Argument "o" isn't numeric in array element at enc.pl line 12, <> line 1.=
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.=
Argument "\n" isn't numeric in array element at enc.pl line 12, <> line 1=
=2E
Argument "^A" isn't numeric in addition (+) at enc.pl line 12, <> line 1.=
Encrypted text now is: e l l o
Note: You should watch out for wrap-arounds ("encrypting" the last=20
letter in the alphabet).
Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Mon, 11 Apr 2005 09:25:09 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Simple Encryption Script
Message-Id: <Vnr6e.15447$yV3.14940@clgrps12>
Nikos wrote:
> #!/usr/bin/perl
use warnings;
use strict;
> print "Enter text to be encrypted: ";
> $toBeEncrypted = <>;
chomp( my $toBeEncrypted = <> );
> @letters = split //, $toBeEncrypted; # load the user input to an array
> letter by letter
No need to convert the string to an array:
$toBeEncrypted =~ tr/a-zA-Z/b-zA-Za/;
print "Encrypted text now is: $toBeEncrypted\n";
John
--
use Perl;
program
fulfillment
------------------------------
Date: 11 Apr 2005 09:48:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Simple Encryption Script
Message-Id: <d3dh4t$6j$2@mamenchi.zrz.TU-Berlin.DE>
John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> Nikos wrote:
> > #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> > print "Enter text to be encrypted: ";
> > $toBeEncrypted = <>;
>
> chomp( my $toBeEncrypted = <> );
>
> > @letters = split //, $toBeEncrypted; # load the user input to an array
> > letter by letter
>
> No need to convert the string to an array:
>
> $toBeEncrypted =~ tr/a-zA-Z/b-zA-Za/;
>
> print "Encrypted text now is: $toBeEncrypted\n";
Not quite. The OPs intended encryption scheme was "chr 1 + ord $c",
so "z" should map to "{" and "Z" to "[". Yours maps "z" to "A" and
"Z" to "a".
Anno
------------------------------
Date: Mon, 11 Apr 2005 09:52:20 +0000 (UTC)
From: Nikos <hackeras@gmail.com>
Subject: Re: Simple Encryption Script
Message-Id: <Xns963582F265D5hackerasgmailcom@194.177.210.210>
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote in news:d3dd5c
$3qb$1@nntp.fujitsu-siemens.com:
> $_ is an alias for the currently selected element of @letters. Also, if
> $_ contains a letter, it contains a letter, not a number, so
> incrementing won't work:
>
> $_ = chr(ord($_) + 1);
thanks here it is now correct:
#!/usr/bin/perl -w
$i=0;
print "Enter text to be encrypted: ";
$text = <>;
chomp($text);
@letters = split //, $text;
foreach (@letters) {
$letters[$i++] = chr( ord($_) + 1 );
}
print "\nEncrypted text now is: @letters\n";
The only proble now is that i get the encryptes text in @letters but with
spaces between each letter ie if encryptes etxt is "idfjs" i get it as "i
d f j s". Why?
It must something in the split part but its the only way i know to get
each letter from a variable. do you know some better way to get the
letter in an array from $text?
--
Just because I didnt doesnt mean I dont want to.
Just because I wouldnt doesnt mean I cant.
------------------------------
Date: Mon, 11 Apr 2005 10:01:01 +0000 (UTC)
From: Nikos <hackeras@gmail.com>
Subject: Re: Simple Encryption Script
Message-Id: <Xns9635846B55A7Fhackerasgmailcom@194.177.210.210>
"John W. Krahn" <someone@example.com> wrote in news:Vnr6e.15447$yV3.14940
@clgrps12:
> Nikos wrote:
>> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
>> print "Enter text to be encrypted: ";
>> $toBeEncrypted = <>;
>
> chomp( my $toBeEncrypted = <> );
why this wotn work?
$toBeEncrypted = chomp (<>);
>> @letters = split //, $toBeEncrypted; # load the user input to an array
>> letter by letter
>
> No need to convert the string to an array:
>
> $toBeEncrypted =~ tr/a-zA-Z/b-zA-Za/;
a-z transletes to b-z
A-Z msut to B-Z why you say A-Za ?
--
Just because I didnt doesnt mean I dont want to.
Just because I wouldnt doesnt mean I cant.
------------------------------
Date: Mon, 11 Apr 2005 10:07:25 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Simple Encryption Script
Message-Id: <x%r6e.15449$yV3.6992@clgrps12>
Nikos wrote:
> Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote in news:d3dd5c
> $3qb$1@nntp.fujitsu-siemens.com:
>
>
>>$_ is an alias for the currently selected element of @letters. Also, if
>>$_ contains a letter, it contains a letter, not a number, so
>>incrementing won't work:
>>
>>$_ = chr(ord($_) + 1);
>
>
> thanks here it is now correct:
>
> #!/usr/bin/perl -w
>
> $i=0;
>
> print "Enter text to be encrypted: ";
> $text = <>;
> chomp($text);
>
> @letters = split //, $text;
>
> foreach (@letters) {
> $letters[$i++] = chr( ord($_) + 1 );
> }
Could be written more simply as:
foreach ( @letters ) {
$_ = chr 1 + ord;
}
> print "\nEncrypted text now is: @letters\n";
>
>
> The only proble now is that i get the encryptes text in @letters but with
> spaces between each letter ie if encryptes etxt is "idfjs" i get it as "i
> d f j s". Why?
perldoc -q "Why do I get weird spaces when I print an array of lines"
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 11 Apr 2005 10:12:16 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Simple Encryption Script
Message-Id: <44s6e.15450$yV3.2725@clgrps12>
Anno Siegel wrote:
> John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
>
>>Nikos wrote:
>>
>>>#!/usr/bin/perl
>>
>>use warnings;
>>use strict;
>>
>>
>>>print "Enter text to be encrypted: ";
>>>$toBeEncrypted = <>;
>>
>>chomp( my $toBeEncrypted = <> );
>>
>>
>>>@letters = split //, $toBeEncrypted; # load the user input to an array
>>>letter by letter
>>
>>No need to convert the string to an array:
>>
>>$toBeEncrypted =~ tr/a-zA-Z/b-zA-Za/;
>>
>>print "Encrypted text now is: $toBeEncrypted\n";
>
>
> Not quite. The OPs intended encryption scheme was "chr 1 + ord $c",
> so "z" should map to "{" and "Z" to "[". Yours maps "z" to "A" and
> "Z" to "a".
Then I guess that this should work:
$toBeEncrypted =~ tr/\0-\xff/\1-\xff\0/;
Or even:
$toBeEncrypted =~ s/(.)/ chr 1 + ord $1 /esg;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 11 Apr 2005 10:19:01 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Simple Encryption Script
Message-Id: <pas6e.15451$yV3.10656@clgrps12>
Nikos wrote:
> "John W. Krahn" <someone@example.com> wrote in news:Vnr6e.15447$yV3.14940
> @clgrps12:
>
>>Nikos wrote:
>>
>>>#!/usr/bin/perl
>>
>>use warnings;
>>use strict;
>>
>>
>>>print "Enter text to be encrypted: ";
>>>$toBeEncrypted = <>;
>>
>>chomp( my $toBeEncrypted = <> );
>
>
> why this wotn work?
>
> $toBeEncrypted = chomp (<>);
Because chomp() returns the number of times that $/ was removed, not the string.
perldoc -f chomp
>>>@letters = split //, $toBeEncrypted; # load the user input to an array
>>>letter by letter
>>
>>No need to convert the string to an array:
>>
>>$toBeEncrypted =~ tr/a-zA-Z/b-zA-Za/;
>
>
> a-z transletes to b-z
> A-Z msut to B-Z why you say A-Za ?
a-z translates to b-zA and A-Z to B-Za, or more explicitly:
abcdefghijklmnopqrstuvwxyz to bcdefghijklmnopqrstuvwxyzA and
ABCDEFGHIJKLMNOPQRSTUVWXYZ to BCDEFGHIJKLMNOPQRSTUVWXYZa
John
--
use Perl;
program
fulfillment
------------------------------
Date: 11 Apr 2005 10:34:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Simple Encryption Script
Message-Id: <d3djrj$3iq$1@mamenchi.zrz.TU-Berlin.DE>
Nikos <hackeras@gmail.com> wrote in comp.lang.perl.misc:
> Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote in news:d3dd5c
> $3qb$1@nntp.fujitsu-siemens.com:
>
> > $_ is an alias for the currently selected element of @letters. Also, if
> > $_ contains a letter, it contains a letter, not a number, so
> > incrementing won't work:
> >
> > $_ = chr(ord($_) + 1);
>
> thanks here it is now correct:
>
> #!/usr/bin/perl -w
>
> $i=0;
>
> print "Enter text to be encrypted: ";
> $text = <>;
> chomp($text);
>
> @letters = split //, $text;
>
> foreach (@letters) {
> $letters[$i++] = chr( ord($_) + 1 );
> }
>
> print "\nEncrypted text now is: @letters\n";
It works now, but it is still somewhat roundabout. You can change
the array elements one by one in the foreach loop, there is no need to
use an index ($i) to access them:
foreach ( @letters ) {
$_ = 1 + chr ord $_;
}
> The only proble now is that i get the encryptes text in @letters but with
> spaces between each letter ie if encryptes etxt is "idfjs" i get it as "i
> d f j s". Why?
This (well, a closely related question) is answered in the FAQ. Use
perldoc -q 'spaces' to find it.
> It must something in the split part but its the only way i know to get
> each letter from a variable. do you know some better way to get the
> letter in an array from $text?
It's not in the split(). You never bothered to join the string together
again, that's what's wrong. In Perl, an array of characters is *not*
the same as a string. You can do it like this:
my $encrypted = join '', map chr 1 + ord, split //, $text;
Alternatively, use a regular expression to access the characters
individually. Encryption happens through the /e modifier of s///
(explained in perlop):
( my $encrypted = $text) =~ s/(.)/chr 1 + ord $1/eg;
Anno
------------------------------
Date: Mon, 11 Apr 2005 08:00:42 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple Encryption Script
Message-Id: <slrnd5kt7q.307.tadmc@magna.augustmail.com>
Nikos <hackeras@gmail.com> wrote:
> "John W. Krahn" <someone@example.com> wrote in news:Vnr6e.15447$yV3.14940
> @clgrps12:
>> chomp( my $toBeEncrypted = <> );
>
> why this wotn work?
>
> $toBeEncrypted = chomp (<>);
Read the docs to see what the chomp() function returns.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 11 Apr 2005 09:53:51 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: UTF-8 in regexp with 5.8.1
Message-Id: <Pine.LNX.4.61.0504110934500.30673@ppepc56.ph.gla.ac.uk>
On Sun, 10 Apr 2005, Wes Groleau wrote:
> I have a file containing thousands of Spanish words, encoded AFAIK)
> in UTF-8.
Well, your whole report stands or falls by that "AFAIK", so it might
be useful to have a test case, including data, which we could run for
ourselves (preferably on a web page, to exclude any possibility of
lossage in usenet postings) to help pin-down your problem.
> I also have a perl script in UTF-8,
Noted, although I don't see any compelling reason to code the script
itself in utf-8. Sure, you /can/ do, but it seems to me to be a
potential additional complication that one could do well to avoid
when feasible.
> #!/usr/bin/perl -w -CSD
> #
> # NOTE: The extra space in the bang line is mandatory (bug in perl 5.8)
Do you have a cite on that? My knowledge of this area is admittedly
somewhat limited, but I hadn't met this before.
> What is in the regexp is supposed to be "small n with tilde"
> and I verified with od -xc that it is hex C3 B1 as is every
> place in the file where that letter appears.
Sounds good. That even seems to have worked in your usenet posting,
as far as I can see.
> use encoding "utf8";
>
> and ran it again, getting only:
> Ze-Admins-Computer:~/Desktop wgroleau$ char-find palabras.utf8
> Malformed UTF-8 character (unexpected non-continuation byte 0x00,
> immediately after start byte 0xde) at
> /Volumes/Parents/wgroleau/bin/char-find line 12.
>
> ?!?
Bizarre.
> According to 'od -xc' the script does NOT contain any
> byte that is 0xde In fact, the ONLY bytes in the script that
> are not ASCII are the bytes for the "enye" which are on line
> twelve, but neither of them is a DE and NO bytes are 00.
I've successfully processed utf-8 and utf-16 data without the use of
the -C flag(s), by using explicit binmode() on the relevant files.
If you could at least get one working variant of your script, you
could then at least move forward from there.
Sorry, this is a bit inconclusive, as yet.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7962
***************************************