[29159] in Perl-Users-Digest
Perl-Users Digest, Issue: 403 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 4 03:10:11 2007
Date: Fri, 4 May 2007 00:09:09 -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 Fri, 4 May 2007 Volume: 11 Number: 403
Today's topics:
Double backslash behavior not as expected alt.testing@{g}mail.com
Re: Double backslash behavior not as expected <someone@example.com>
Re: Double backslash behavior not as expected alt.testing@{g}mail.com
Re: Double backslash behavior not as expected <m@rtij.nl.invlalid>
Downloading a .exe file with Apache and Perl <lmmendoza@go.com>
Re: Downloading a .exe file with Apache and Perl <spamtrap@dot-app.org>
Re: Downloading a .exe file with Apache and Perl <lmmendoza@go.com>
Re: hello world with perl <invalid@invalid.nyet>
Re: Interval Timers on Windows sl123@netherlands.area
new CPAN modules on Fri May 4 2007 (Randal Schwartz)
octal and hex interpreter.maladies@gmail.com
Re: octal and hex <joe@inwap.com>
Re: octal and hex <attn.steven.kuo@gmail.com>
Re: octal and hex <josef.moellers@fujitsu-siemens.com>
Re: PERL OOP newbie question: What is the best way to h <joe@inwap.com>
Re: remove html to leave text <joe@inwap.com>
Re: Web Forms / Perl / SPAM detection <noreply@gunnar.cc>
Re: Web Forms / Perl / SPAM detection <vilain@spamcop.net>
Re: Web Forms / Perl / SPAM detection <noreply@gunnar.cc>
Re: Why stay with lisp when there are python and perl? <jon@ffconsultancy.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 04 May 2007 12:06:54 +1000
From: alt.testing@{g}mail.com
Subject: Double backslash behavior not as expected
Message-Id: <9m3l33pduh1tdd4a9528lnjvgnp3tjn2qr@4ax.com>
Hi all,
the simple concept of escaping a "backslash", thus translating to a
literal backslash; does not provide the implied result, under the
following example.
$mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
/mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
password=$pass#;
The top part of the "strace" output gives this:
execve("/bin/mount", ["/bin/mount", "-t", "smbfs", "\\an2documents",
"/mnt/workstation_shares/xxxx/doc"..., "-o", "ro", "-o",
"username=xxxx", "-o", "password=xxxxxxxxxx"], [/* 22 vars */]) = 0
"\\an2documents"
Note; that there is no "\" in between the machine name, and the share.
It should be "\\an2\documents".
[root@mercedes sbin]# perl -e 'print "\\\\an2\\documents\n"'
\\an2\documents
I'm sure it's a simple thing, but can someone enlighten me on this
parlay?
ta.
Full Context
===============================================================================
#!/usr/bin/perl
use strict;
use warnings;
my $input_vars_file = "/usr/local/etc/priv/users_test";
my $tmp_vars;
my $input_vars;
my @input_vars_array;
my @target_vars_array;
my $user;
my $pass;
my $machine;
my $mount;
my $mount_result;
open ( IN_FILE, "< $input_vars_file") or die "$!";
while ( <IN_FILE> ){
$tmp_vars = $_;
$tmp_vars =~ s/(\s+)/,/g;
$tmp_vars =~ s/;.*$//g;
@input_vars_array = split( /,/, $tmp_vars );
push @target_vars_array, [ @input_vars_array ] unless ( /^\W/ );
}
close IN_FILE;
for my $counter ( 0 .. $#target_vars_array ) {
$user = $target_vars_array[$counter][0];
$pass = $target_vars_array[$counter][1];
$machine = $target_vars_array[$counter][2];
$mount = $target_vars_array[$counter][3];
print "$user, $pass, $machine, $mount\n";
$mount_result = qx#/bin/mount#;
if ( $mount_result =~ /$machine\/documents/ ) {
print "$machine: already mounted\n";
}
else {
$mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
/mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
password=$pass#;
}
print "$mount_result\n";
}
exit
------------------------------
Date: Fri, 04 May 2007 02:44:00 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Double backslash behavior not as expected
Message-Id: <Q5x_h.1690$Vi6.1400@edtnps82>
alt.testing@{g}mail.com wrote:
> Hi all,
> the simple concept of escaping a "backslash", thus translating to a
> literal backslash; does not provide the implied result, under the
> following example.
>
> $mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
> /mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
> password=$pass#;
>
> The top part of the "strace" output gives this:
>
> execve("/bin/mount", ["/bin/mount", "-t", "smbfs", "\\an2documents",
> "/mnt/workstation_shares/xxxx/doc"..., "-o", "ro", "-o",
> "username=xxxx", "-o", "password=xxxxxxxxxx"], [/* 22 vars */]) = 0
>
> "\\an2documents"
>
> Note; that there is no "\" in between the machine name, and the share.
> It should be "\\an2\documents".
>
> [root@mercedes sbin]# perl -e 'print "\\\\an2\\documents\n"'
> \\an2\documents
>
>
> I'm sure it's a simple thing, but can someone enlighten me on this
> parlay?
Your string is interpolated twice, once by perl and then by the shell.
$ perl -le'
$machine = "an2";
$mount = "xxxx";
print qx#echo /bin/mount -t smbfs
\\\\$machine\\documents/mnt/workstation_shares/$mount/documents/#;
'
/bin/mount -t smbfs \an2documents/mnt/workstation_shares/xxxx/documents/
You need to double up on the back-slashes.
$ perl -le'
$machine = "an2";
$mount = "xxxx";
print qx#echo /bin/mount -t smbfs
\\\\\\\\$machine\\\\documents/mnt/workstation_shares/$mount/documents/#;
'
/bin/mount -t smbfs \\an2\documents/mnt/workstation_shares/xxxx/documents/
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
------------------------------
Date: Fri, 04 May 2007 13:13:35 +1000
From: alt.testing@{g}mail.com
Subject: Re: Double backslash behavior not as expected
Message-Id: <nu8l3316q1dm64eg6ta349flcsmpchvlqo@4ax.com>
On Fri, 04 May 2007 02:44:00 GMT, "John W. Krahn"
<someone@example.com> wrote:
>alt.testing@{g}mail.com wrote:
>> Hi all,
>> the simple concept of escaping a "backslash", thus translating to a
>> literal backslash; does not provide the implied result, under the
>> following example.
>>
>> $mount_result = qx#strace /bin/mount -t smbfs \\\\$machine\\documents
>> /mnt/workstation_shares/$mount/documents/ -o ro -o username=$user -o
>> password=$pass#;
>>
>> The top part of the "strace" output gives this:
>>
>> execve("/bin/mount", ["/bin/mount", "-t", "smbfs", "\\an2documents",
>> "/mnt/workstation_shares/xxxx/doc"..., "-o", "ro", "-o",
>> "username=xxxx", "-o", "password=xxxxxxxxxx"], [/* 22 vars */]) = 0
>>
>> "\\an2documents"
>>
>> Note; that there is no "\" in between the machine name, and the share.
>> It should be "\\an2\documents".
>>
>> [root@mercedes sbin]# perl -e 'print "\\\\an2\\documents\n"'
>> \\an2\documents
>>
>>
>> I'm sure it's a simple thing, but can someone enlighten me on this
>> parlay?
>
>Your string is interpolated twice, once by perl and then by the shell.
>
>$ perl -le'
>$machine = "an2";
>$mount = "xxxx";
>print qx#echo /bin/mount -t smbfs
>\\\\$machine\\documents/mnt/workstation_shares/$mount/documents/#;
>'
>/bin/mount -t smbfs \an2documents/mnt/workstation_shares/xxxx/documents/
>
>
>You need to double up on the back-slashes.
>
>$ perl -le'
>$machine = "an2";
>$mount = "xxxx";
>print qx#echo /bin/mount -t smbfs
>\\\\\\\\$machine\\\\documents/mnt/workstation_shares/$mount/documents/#;
>'
>/bin/mount -t smbfs \\an2\documents/mnt/workstation_shares/xxxx/documents/
>
Thanks John,
Nick
>
>
>John
------------------------------
Date: Fri, 4 May 2007 07:45:43 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: Double backslash behavior not as expected
Message-Id: <pan.2007.05.04.05.45.43@rtij.nl.invlalid>
On Fri, 04 May 2007 02:44:00 +0000, John W. Krahn wrote:
> Your string is interpolated twice, once by perl and then by the shell.
>
> $ perl -le'
> $machine = "an2";
> $mount = "xxxx";
> print qx#echo /bin/mount -t smbfs
> \\\\$machine\\documents/mnt/workstation_shares/$mount/documents/#; '
> /bin/mount -t smbfs \an2documents/mnt/workstation_shares/xxxx/documents/
>
>
> You need to double up on the back-slashes.
Or use forward slashes. That also works for smb paths with smbmount and
this shows why....
HTH,
M4
------------------------------
Date: 3 May 2007 20:36:29 -0700
From: LMario <lmmendoza@go.com>
Subject: Downloading a .exe file with Apache and Perl
Message-Id: <1178249789.355958.58370@l77g2000hsb.googlegroups.com>
I am using the next Perl Script to download a .exe file:
The file can be download complete (well almost: Opera send a error
when the download finishes) by the brownser but it arrives corrupted.
I mean it can=B4t be executed. It is windows application and when a
execute the downloaded file appears a DOS window, which send the error
message "The file can't be executed in DOS mode".
I don't know if I am not generating the apropiate headeres with the
Perl Script or if I need configurate something with Apache
-Text files can be download well with the script.
#!E:\Perl5p8p8\bin\perl.exe -wT
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $file_location;
my $filename;
my $filesize;
my @fileholder;
$file_location =3D "D:\\MiSitioWEB\\SPE\\cgi-bin";
$filename =3D 'Setup.exe';
$filesize =3D -s "$file_location\\$filename";
open(DLFILE, "<$file_location\\$filename") ||
Error('abrir','archivo');
@fileholder =3D <DLFILE>;
close (DLFILE) || Error ('close','file');
open(LOG,">>D:\\MiSitioWEB\\SPE\\cgi-bin\\ContDesSPE.log")||
Error('abrir','archivo');
print LOG "$filename\n";
close(LOG);
print "Content-length: $filesize\n";
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=3D$filename\n\n";
print @fileholder;
exit;
sub Error
{
print "Content-type: text/html\n\n";
print "El servidor no puede $_[0] el $_[1]: $! \n";
exit;
}
------------------------------
Date: Fri, 04 May 2007 00:03:41 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Downloading a .exe file with Apache and Perl
Message-Id: <m2bqh11bhe.fsf@local.wv-www.com>
LMario <lmmendoza@go.com> writes:
> I am using the next Perl Script to download a .exe file:
>
> The file can be download complete (well almost: Opera send a error
> when the download finishes) by the brownser but it arrives corrupted.
> I mean it canīt be executed. It is windows application and when a
> execute the downloaded file appears a DOS window, which send the error
> message "The file can't be executed in DOS mode".
>
> I don't know if I am not generating the apropiate headeres with the
> Perl Script or if I need configurate something with Apache
Judging by the path names you're using, it looks like your server is some
flavor of Windows. On Windows, you need to change STDOUT to use binary mode
before sending binary data:
binmode STDOUT;
> print "Content-length: $filesize\n";
> print "Content-Type:application/x-download\n";
> print "Content-Disposition:attachment;filename=$filename\n\n";
> print @fileholder;
> exit;
You don't need to call exit() here, since there is no more code to run
past this point.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 3 May 2007 22:25:25 -0700
From: LMario <lmmendoza@go.com>
Subject: Re: Downloading a .exe file with Apache and Perl
Message-Id: <1178256325.126962.203610@c35g2000hsg.googlegroups.com>
Thanks Sherm, now is working.
On 3 mayo, 22:03, Sherm Pendley <spamt...@dot-app.org> wrote:
> LMario <lmmend...@go.com> writes:
> > I am using the next Perl Script todownloada .exefile:
>
> > The file can bedownloadcomplete (well almost: Opera send a error
> > when thedownloadfinishes) by the brownser but it arrives corrupted.
> > I mean it can=B4t be executed. It is windows application and when a
> > execute the downloaded file appears a DOS window, which send the error
> > message "The file can't be executed in DOS mode".
>
> > I don't know if I am not generating the apropiate headeres with the
> > Perl Script or if I need configurate something with Apache
>
> Judging by the path names you're using, it looks like your server is some
> flavor of Windows. On Windows, you need to change STDOUT to use binary mo=
de
> before sending binary data:
>
> binmode STDOUT;
>
> > print "Content-length: $filesize\n";
> > print "Content-Type:application/x-download\n";
> > print "Content-Disposition:attachment;filename=3D$filename\n\n";
> > print @fileholder;
> > exit;
>
> You don't need to call exit() here, since there is no more code to run
> past this point.
>
> sherm--
>
> --
> Web Hosting by West Virginians, for West Virginians:http://wv-www.net
> Cocoa programming in Perl:http://camelbones.sourceforge.net
------------------------------
Date: Thu, 3 May 2007 22:29:19 -0400
From: "Wade Ward" <invalid@invalid.nyet>
Subject: Re: hello world with perl
Message-Id: <IfGdnbDhuK4YB6fbnZ2dnUVZWhednZ2d@comcast.com>
"Ian Wilson" <scobloke2@infotop.co.uk> wrote in message
news:46399e81$0$21838$db0fefd9@news.zen.co.uk...
> Wade Ward wrote:
>>
>> 'perl' is not recognized as a command.
>
> Download and install ActivePerl.
I installed ActivePerl in c:\perl\ and found perl.exe in c:\perl\bin\. I
changed komodo so that the command line finds perl.exe and do, at long last,
have hello world. I really appreciate your help:-)
--
WW
------------------------------
Date: Thu, 03 May 2007 20:58:44 -0700
From: sl123@netherlands.area
Subject: Re: Interval Timers on Windows
Message-Id: <ar2l33pdc7kr8rlen3obemcp4tk8funop0@4ax.com>
On Tue, 01 May 2007 21:04:26 -0700, sl123@netherlands.area wrote:
I was curious about this so I tried this thread model, sending packets
on a time boundry. Virtually no drift, mean stayed on target at %99.98.
Actually I was suprised.
>On Sun, 29 Apr 2007 16:40:11 +0800, Bernard Chan <cbkihong@hotmail.com> wrote:
>
>>
>>Hi All,
>>
>>I am writing a script to generate some packets for RTP stream simulation. As
>>you may know, RTP requires a more-or-less constant packet rate (and hence
>>UDP is used), and I will need to generate fixed sized packets at regular
>>intervals, say 20ms, so that will be around 50 packets per second.
>>
<snip>
>>--
>>Regards,
>>Bernard Chan
>
>Hey, not sure if this will work but its worth a try.
>Some pseudo perl code to try out.
>Typically on Windows this is realatively easy to start the send packet on a time increment
>boundry. Done with signals, multiple threads and non-blocking WaitForMultipleObjects();
>
>Not sure in Perl if you can set the thread priorities but the timer thread would get a little higher.
>
>
>
>packet_available = 0;
>packet_sequence = 1;
>kill_threads = 0;
>
>main()
>{
> # start Packet_thread();
> # start Timer_thread();
> while (packet_sequence < 500)
> {
> # you can try a sleep here of 5ms but I don't think its necessary
> sleep(5);
> }
> kill_threads = 1;
> sleep(500);
>}
>
>
>Timer_thread()
>{
> while (!kill_threads)
> {
> sleep(20);
> packet_sequence++;
> packet_available = 1;
> }
>}
>
>Packet_thread()
>{
> last_packet_sequence = 0;
> while (!kill_threads)
> {
> if (packet_available)
> {
> Send_Packet();
> # do something with the sequence
> # to see if we missed one
> if (packet_sequence != last_packet_sequence+1)
> {
> print "race condition, missed packet, expected ...\n";
> }
> last_packet_sequence = packet_sequence;
> Load_Next_Packet_Data();
> packet_available = 0;
> }
> # you can try a sleep here of 1ms but I don't think its necessary
> # sleep(1);
> }
>}
>
>
------------------------------
Date: Fri, 4 May 2007 04:42:10 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Fri May 4 2007
Message-Id: <JHI2EA.1183@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
AI-Prolog-0.738
http://search.cpan.org/~jjore/AI-Prolog-0.738/
Perl extension for logic programming.
----
Agent-TCLI-0.032
http://search.cpan.org/~hacker/Agent-TCLI-0.032/
Transactional Contextual Line Interface
----
Agent-TCLI-Package-Net-0.020
http://search.cpan.org/~hacker/Agent-TCLI-Package-Net-0.020/
----
BatchSystem-SBS-0.32
http://search.cpan.org/~alexmass/BatchSystem-SBS-0.32/
a Simple Batch System
----
CGI-PathRequest-1.18
http://search.cpan.org/~leocharre/CGI-PathRequest-1.18/
get file info in a cgi environment
----
Class-C3-0.16
http://search.cpan.org/~blblack/Class-C3-0.16/
A pragma to use the C3 method resolution order algortihm
----
Class-C3-XS-0.02
http://search.cpan.org/~blblack/Class-C3-XS-0.02/
XS speedups for Class::C3
----
DBIx-Perlish-0.24
http://search.cpan.org/~gruber/DBIx-Perlish-0.24/
a perlish interface to SQL databases
----
Data-Alias-1.04
http://search.cpan.org/~xmath/Data-Alias-1.04/
Comprehensive set of aliasing operations
----
Data-Currency-0.04000
http://search.cpan.org/~claco/Data-Currency-0.04000/
Container class for currency conversion/formatting
----
Data-RuledValidator-Plugin-Japanese-0.04
http://search.cpan.org/~ktat/Data-RuledValidator-Plugin-Japanese-0.04/
Data::RuledValidator plugin for Japanese
----
Data-Visitor-Encode-0.07
http://search.cpan.org/~dmaki/Data-Visitor-Encode-0.07/
Encode/Decode Values In A Structure
----
Email-Send-TheSchwartz-0.01
http://search.cpan.org/~btrott/Email-Send-TheSchwartz-0.01/
Send Messages using TheSchwartz
----
Image-Magick-Thumbnail-PDF-1.05
http://search.cpan.org/~leocharre/Image-Magick-Thumbnail-PDF-1.05/
make thumbnail of a page in a pdf document
----
InSilicoSpectro-1.0.18
http://search.cpan.org/~alexmass/InSilicoSpectro-1.0.18/
Open source Perl library for proteomics
----
JSON-1.12
http://search.cpan.org/~makamaka/JSON-1.12/
parse and convert to JSON (JavaScript Object Notation).
----
Lingua-PT-ProperNames-0.07
http://search.cpan.org/~ambs/Lingua-PT-ProperNames-0.07/
Simple module to extract proper names from Portuguese Text
----
Linux-SysInfo-0.04
http://search.cpan.org/~vpit/Linux-SysInfo-0.04/
Perl interface to the sysinfo(2) Linux system call.
----
Mail-Outlook-0.11
http://search.cpan.org/~barbie/Mail-Outlook-0.11/
mail module to interface with Microsoft (R) Outlook (R).
----
Metadata-ByInode-1.12
http://search.cpan.org/~leocharre/Metadata-ByInode-1.12/
Extend metadata in relation to file's inode using a database.
----
Module-Refresh-0.13
http://search.cpan.org/~jesse/Module-Refresh-0.13/
Refresh %INC files when updated on disk
----
Module-Release-1.16
http://search.cpan.org/~bdfoy/Module-Release-1.16/
Automate software releases
----
MogileFS-Client-1.07
http://search.cpan.org/~bradfitz/MogileFS-Client-1.07/
Client library for the MogileFS distributed file system.
----
MogileFS-Utils-2.09
http://search.cpan.org/~bradfitz/MogileFS-Utils-2.09/
----
Moose-0.21
http://search.cpan.org/~stevan/Moose-0.21/
A complete modern object system for Perl 5
----
POE-Component-IRC-5.29
http://search.cpan.org/~bingos/POE-Component-IRC-5.29/
a fully event-driven IRC client module.
----
POE-Component-Server-SimpleSMTP-1.02
http://search.cpan.org/~bingos/POE-Component-Server-SimpleSMTP-1.02/
A simple to use POE SMTP Server.
----
Parallel-Fork-BossWorker-0.03
http://search.cpan.org/~jrod/Parallel-Fork-BossWorker-0.03/
Perl extension for easiliy creating forking queue processing applications.
----
SyslogScan-Daemon-SpamDetector-0.55
http://search.cpan.org/~muir/SyslogScan-Daemon-SpamDetector-0.55/
Notice spammers in the log files
----
Test-OpenID-Consumer-0.01
http://search.cpan.org/~jesse/Test-OpenID-Consumer-0.01/
setup a simulated OpenID consumer
----
Test-OpenID-Server-0.01
http://search.cpan.org/~jesse/Test-OpenID-Server-0.01/
setup a simulated OpenID server
----
Text-Aspell-0.08
http://search.cpan.org/~hank/Text-Aspell-0.08/
Perl interface to the GNU Aspell library
----
Text-OutputFilter-0.12
http://search.cpan.org/~hmbrand/Text-OutputFilter-0.12/
Filter and modify output
----
Text-Restructured-0.003028
http://search.cpan.org/~nodine/Text-Restructured-0.003028/
Perl implementation of reStructuredText parser
----
Tie-RefHash-Weak-0.02
http://search.cpan.org/~nuffin/Tie-RefHash-Weak-0.02/
A Tie::RefHash subclass with weakened references in the keys.
----
Time-Elapsed-0.16
http://search.cpan.org/~burak/Time-Elapsed-0.16/
Displays the elapsed time as a human readable string.
----
WWW-Facebook-API-v0.0.6
http://search.cpan.org/~unobe/WWW-Facebook-API-v0.0.6/
Facebook API implementation
----
WWW-Scraper-ISBN-TWEslitebooks_Driver-0.02
http://search.cpan.org/~ijliao/WWW-Scraper-ISBN-TWEslitebooks_Driver-0.02/
Search driver for TWEslitebooks' online catalog.
----
WWW-Slides-0.0.6
http://search.cpan.org/~polettix/WWW-Slides-0.0.6/
serve presentations on the Web
----
WWW-Slides-v0.0.4
http://search.cpan.org/~polettix/WWW-Slides-v0.0.4/
serve presentations on the Web
----
Want-0.13
http://search.cpan.org/~robin/Want-0.13/
A generalisation of wantarray
----
kurila-0_02
http://search.cpan.org/~tty/kurila-0_02/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
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: 3 May 2007 20:22:59 -0700
From: interpreter.maladies@gmail.com
Subject: octal and hex
Message-Id: <1178248979.568580.132980@p77g2000hsh.googlegroups.com>
I can't figure out how to detect the difference between an octal and a
hex string such as so:
my $text1 = "\110ello";
my $text2 = "\x48ello";
Both expressions /[\x00-\x7f]/ and /[\000-\177]/ match both strings
unfortunately.
Is there a way to match an octal but not a hex character, and
conversely, match a hex character but not an octal?
Much thanks in advance.
------------------------------
Date: Thu, 03 May 2007 22:28:09 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: octal and hex
Message-Id: <VJ-dncYicOP2WafbnZ2dnUVZ_hKdnZ2d@comcast.com>
interpreter.maladies@gmail.com wrote:
> I can't figure out how to detect the difference between an octal and a
> hex string such as so:
>
> my $text1 = "\110ello";
> my $text2 = "\x48ello";
There is absolutely no difference between those two, once perl's input
parser has processed them.
> Both expressions /[\x00-\x7f]/ and /[\000-\177]/ match both strings
> unfortunately.
You're on the wrong track since both expressions match all 128 7-bit ASCII characters.
> Is there a way to match an octal but not a hex character, and
> conversely, match a hex character but not an octal?
All legal octal characters are legal hex characters.
Can you restate the problem?
If you want to match a single one-byte character specified octal notation and convert
that back to a single byte:
$string =~ s/\\([0-7]{1,3})/chr oct $1/eg;
If you want to match a single one-byte character specified hex notation and convert
that back to a single byte:
$string =~ s/\\x([0-9a-f]{1,2})/chr hex $1/ieg;
Handling multi-byte characters or UTF-8 notation takes more work.
-Joe
------------------------------
Date: 3 May 2007 22:37:24 -0700
From: "attn.steven.kuo@gmail.com" <attn.steven.kuo@gmail.com>
Subject: Re: octal and hex
Message-Id: <1178257044.679241.153290@u30g2000hsc.googlegroups.com>
On May 3, 8:22 pm, interpreter.malad...@gmail.com wrote:
> I can't figure out how to detect the difference between an octal and a
> hex string such as so:
>
> my $text1 = "\110ello";
> my $text2 = "\x48ello";
>
> Both expressions /[\x00-\x7f]/ and /[\000-\177]/ match both strings
> unfortunately.
>
> Is there a way to match an octal but not a hex character, and
> conversely, match a hex character but not an octal?
>
> Much thanks in advance.
Those are interpolated strings. Although
they differ notationally as *code*, their values
(as *data*) are the same. You can't distinguish
between their values. No more than you're able
to distinguish the values of $a and $b when
written as:
my $a = 8; # decimal
my $b = 010; # octal
if ($a == $b) {
print "$a and $b are the SAME\n";
}
Literal strings (in single quotes) are a
different story. Contrast:
my $a = "\110ello";
my $b = "\x48ello";
if ($a eq $b) {
print "$a and $b are the SAME\n";
}
$a = '\\110ello';
$b = '\\x48ello';
my $eval_a = eval "\"$a\"";
my $eval_b = eval "\"$b\"";
unless ($a eq $b) {
print '$a and $b differ', "\n";
}
if ($eval_a eq $eval_b) {
print "interpolation of $a and $b yield the same value\n";
}
--
Hope this helps,
Steven
------------------------------
Date: Fri, 04 May 2007 09:02:03 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: octal and hex
Message-Id: <f1elph$5lp$1@nntp.fujitsu-siemens.com>
interpreter.maladies@gmail.com wrote:
> I can't figure out how to detect the difference between an octal and a
> hex string such as so:
>=20
> my $text1 =3D "\110ello";
> my $text2 =3D "\x48ello";
>=20
>=20
> Both expressions /[\x00-\x7f]/ and /[\000-\177]/ match both strings
> unfortunately.
>=20
> Is there a way to match an octal but not a hex character, and
> conversely, match a hex character but not an octal?
>=20
> Much thanks in advance.
>=20
You mix up external and internal representations:
'a', "\x61", "\141" are arr different external representations for the=20
internal bit pattern 01100001 (assuming ASCII).
So, once perl has processed one of these you can't determine what the=20
external representation has been.
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Thu, 03 May 2007 21:53:38 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: PERL OOP newbie question: What is the best way to handle array data?
Message-Id: <D8adnRWQcorOIafbnZ2dnUVZ_jmdnZ2d@comcast.com>
lovellj@mcmaster.ca wrote:
> I tried assigning $self->{'data_array'} = ("MON","TUE","WED"), but
> then I found when I try to access this data, the array gets messed up
> and it comes out as a scalar or as the last value in the array.
That is correct; the comma operator in scalar context does exactly that.
You'll need to know when it is appropriate to use [] instead of ().
Using an array:
@array = ("MON","TUE","WED");
@array = qw(MON TUE WED);
Using a scalar (a reference to an anonymous array):
$array_ref = ["MON","TUE","WED"];
$array_ref = [qw(MON TUE WED)];
$self->{'data_array'} = [ qw(SUN MON TUE WED THU FRI SAT) ];
-Joe
------------------------------
Date: Thu, 03 May 2007 22:39:05 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: remove html to leave text
Message-Id: <noidnZWv_r9mW6fbnZ2dnUVZ_vGinZ2d@comcast.com>
Sherm Pendley wrote:
> ton de w <ton_de_winter@yahoo.co.uk> writes:
>
>> How can I strip out the html tags <b> etc etc and replace each tag
>> with a char of my choice?
>
> That's a Frequently Asked Question:
>
> perldoc -q 'remove HTML'
"The most correct way (albeit not the fastest) is to use HTML::Parser from CPAN."
If you're too impatient to read through all of docs, here's a hint on usage:
#!/usr/bin/perl
# Name: nohtml Author: Joe.Smith@inwap.com 07-Nov-2001
# Purpose: Extracts just the text portions of a document.
use strict; use warnings;
use HTML::Parser ();
sub text_handler { print @_; } # Ordinary text
my $p = HTML::Parser->new(api_version => 3);
$p->handler( text => \&text_handler, "dtext");
$p->parse_file(shift || "-") || die $!;
------------------------------
Date: Fri, 04 May 2007 00:31:28 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Web Forms / Perl / SPAM detection
Message-Id: <59v6aiF2mpcv3U1@mid.individual.net>
Brian Wakem wrote:
> - Bob - wrote:
>>I am hoping to avoid the "enter this displayed secret code"
>>mechanism as an annoyance for legit users. But, I am open to
>>suggestions on existing Perl based solutions (trails blazed before
>>me!) or just pointers to good resources on programmable solutions to
>>this issue.
I don't like CAPTCHA either.
The CPAN module CGI::ContactForm includes a cookie based spam prevention
feature. It's not waterproof, but it does stop some of the bots.
> When a load of link spamming bots were hitting our contact forms I found
> that ignoring any message with '</a>' or '[/url]' in got rid of 99% of the
> crap.
I suppose that would stop the rest of the bots for me too.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 03 May 2007 15:52:29 -0700
From: Michael Vilain <vilain@spamcop.net>
Subject: Re: Web Forms / Perl / SPAM detection
Message-Id: <vilain-36078A.15522903052007@comcast.dca.giganews.com>
In article <ihpj33le6br0jo7lfqmd6quq7anrnem7pl@4ax.com>,
- Bob - <uctraing@ultranet.com> wrote:
> I have some web forms that are getting hit by spammers sending spam
> into the system. They are simple forms, add your name, address, etc.
> Perl code handles the form, of course!
>
> I'd like to cut down on the spammers. I was thinking that perhaps I
> could check the person's IP against blacklists... but most of the
> blacklists I know of are mail servers, so I am not sure that is
> practical. I am hoping to avoid the "enter this displayed secret code"
> mechanism as an annoyance for legit users. But, I am open to
> suggestions on existing Perl based solutions (trails blazed before
> me!) or just pointers to good resources on programmable solutions to
> this issue.
>
> Thanks,
>
My contact page was getting hit by spammers and I tried for a while to
us a block list. It became to burdensome to constantly update it. I
was ready to implement a CAPTCHA but found a really quick solution.
I renamed all the fields to generic names (e.g. FIELD1, FIELD2, etc.)
and added a HIDDEN field which I gave a default value of "" in the form.
In the form processing script (this was PHP, but it will work in PERL
also), if the hidden field has a non-blank value, I know a BOT has
filled out the form and I don't process it further. Only a human
filling out the form and pressing SUBMIT will process it.
Simple and it seems to work. No BOTs have sent me email for a while now.
--
DeeDee, don't press that button! DeeDee! NO! Dee...
------------------------------
Date: Fri, 04 May 2007 03:02:10 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Web Forms / Perl / SPAM detection
Message-Id: <59vf54F2n2b3tU1@mid.individual.net>
Michael Vilain wrote:
> I renamed all the fields to generic names (e.g. FIELD1, FIELD2, etc.)
> and added a HIDDEN field which I gave a default value of "" in the form.
> In the form processing script (this was PHP, but it will work in PERL
> also), if the hidden field has a non-blank value, I know a BOT has
> filled out the form and I don't process it further. Only a human
> filling out the form and pressing SUBMIT will process it.
>
> Simple and it seems to work. No BOTs have sent me email for a while now.
Interesting. Do you know if it's the generic names or the hidden fields
that is the key of success? Or is it the combination?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 04 May 2007 03:06:15 +0100
From: Jon Harrop <jon@ffconsultancy.com>
Subject: Re: Why stay with lisp when there are python and perl?
Message-Id: <463a9668$0$8719$ed2619ec@ptn-nntp-reader02.plus.net>
Nameless wrote:
> Why should I keep on learning lisp when there are python and perl?
Lisp compilers are much more advanced, for one thing.
Xah Lee wrote:
> (if there is some demand, i will add a concrept, little programing
> example, that shows, how lisp's symbols and macros concepts, set it
> apart from new scripting languages)
I already did something similar, writing simple programs to simplify
symbolic expressions in different languages:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/239715
Also, here is a symbolic derivative example:
http://codecodex.com/wiki/index.php?title=Derivative
Note that pattern matching (as found in OCaml, F#, Haskell etc.) is very
useful for this kind of term rewriting and is not found in Python, Perl or
Lisp.
> This lisp's symbol concept, as far as i know, does not exist in some
> other high-level functional programing languages such as Haskell.
Correct.
> I'm
> not familiar with many functional languages except Lisp and
> Mathematica. I'm curious, as to how Haskell, which itself is quite
> with capable of symbolic computation i think, deals with it even
> though the language doesn't employ the concep of lisp's symbols per
> se.
In Standard ML, Haskell and F# you must define a sum type that represents a
symbolic expression whereas, in Lisp, you can use the built-in
s-expressions. The sum type that you define typically includes a "Symbol"
that carries its string name. For example, the F# code cited above used:
type expr =
| Int of int
| Add of expr * expr
| Mul of expr * expr
| Var of string with
static member ( + ) (f, g) = Add(f, g)
static member ( * ) (f, g) = Mul(f, g)
end
in this case, "Var" represents a symbol, e.g. the value Var "x" would
represent a variable x.
However, note that the best Lisp implementation of the symbolic simplifier
(by Pascal Constanza) avoids s-expressions, improving performance.
In OCaml, you can rely on the compiler inferring the sum type for you by
using polymorphic variants. However, this is not generally a good idea
because they are slower and harbor some of the disadvantages of dynamic
typing.
It is worth noting that eager, statically-typed languages like OCaml and F#
are many times faster than the other languages at this task. This is
precisely the forte of OCaml and F#, manipulating trees and graphs.
--
Dr Jon D Harrop, Flying Frog Consultancy
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?usenet
------------------------------
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 V11 Issue 403
**************************************