[29545] in Perl-Users-Digest
Perl-Users Digest, Issue: 789 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 24 06:09:42 2007
Date: Fri, 24 Aug 2007 03:09:08 -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, 24 Aug 2007 Volume: 11 Number: 789
Today's topics:
best practice ... requires <hillmw@charter.net>
Re: best practice ... requires <noreply@gunnar.cc>
Re: better hachage <tadmc@seesig.invalid>
Re: Efficiently de-duping an array <dan.otterburn@gmail.com>
Re: Efficiently de-duping an array <tadmc@seesig.invalid>
Re: Efficiently de-duping an array <noreply@gunnar.cc>
Re: Efficiently de-duping an array <tadmc@seesig.invalid>
Re: Efficiently de-duping an array <dan.otterburn@gmail.com>
How safe is $0? <bill@ts1000.us>
How to install WIN32::CGI on ActiveState Perl instaled <Bond@james.bond>
Is there a better way of doing this? <bill@ts1000.us>
Re: Is there a perl equivalent to the following.... <spamtrap@dot-app.org>
new CPAN modules on Fri Aug 24 2007 (Randal Schwartz)
Re: Rename Perl Process <wogri.wogri@gmail.com>
Re: Script does not want to run in background ?!? <joe@inwap.com>
Split strings chinmoy.chittaranjan@gmail.com
Re: Split strings anno4000@radom.zrz.tu-berlin.de
Re: Split strings <dan.otterburn@gmail.com>
Re: Symbolic representation of logical operators <tadmc@seesig.invalid>
Re: Symbolic representation of logical operators <bik.mido@tiscalinet.it>
Re: Symbolic representation of logical operators <hjp-usenet2@hjp.at>
Threaded Perl Processes Going to Sleep Simultaneously?? <Roycedot@gmail.com>
Re: UTF-8 problem <joe@inwap.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 23 Aug 2007 18:39:20 -0700
From: mike <hillmw@charter.net>
Subject: best practice ... requires
Message-Id: <1187919560.101037.175520@x35g2000prf.googlegroups.com>
i'm having trouble with variables
I have a main cgi script ... lets call it main.cgi
In main.cgi i have some other perl scripts that have subroutines
#!/usr/bin/perl -w
#
# name of this program is: main.cgi
#
use CGI;
use Cwd; #used to get the current working directory
$filebase = cwd;
#requires here
require "$filebase/some.lib";
require "$filebase/a.pl";
require "$filebase/b.pl";
require "$filebase/c.pl";
my $x = &do this;
So the question is:
1) if i dont use a subroutine that is in some.lib here in main.cgi but
in a.pl is it better to remove the require from main.cgi and put it in
a.pl?
2) can my require in main.cgi be global since the vars in some.lib are
used in a.pl, b.pl, and c.pl?
thanks 4 any help.
Mike
------------------------------
Date: Fri, 24 Aug 2007 04:04:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: best practice ... requires
Message-Id: <5j6sm0F3qja12U1@mid.individual.net>
mike wrote:
> i'm having trouble with variables
What kind of trouble??
> I have a main cgi script ... lets call it main.cgi
>
> In main.cgi i have some other perl scripts that have subroutines
>
> #!/usr/bin/perl -w
> #
> # name of this program is: main.cgi
> #
>
> use CGI;
> use Cwd; #used to get the current working directory
> $filebase = cwd;
>
> #requires here
> require "$filebase/some.lib";
> require "$filebase/a.pl";
> require "$filebase/b.pl";
> require "$filebase/c.pl";
>
> my $x = &do this;
>
> So the question is:
> 1) if i dont use a subroutine that is in some.lib here in main.cgi but
> in a.pl is it better to remove the require from main.cgi and put it in
> a.pl?
If you also import symbols from some.lib and the subroutines are in a
separate package, it's better to require the library from the script
that is using the subs. Otherwise it doesn't matter.
> 2) can my require in main.cgi be global since the vars in some.lib are
> used in a.pl, b.pl, and c.pl?
What does "global" mean here?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 24 Aug 2007 01:31:43 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: better hachage
Message-Id: <slrnfcsd6q.4sg.tadmc@tadmc30.sbcglobal.net>
john.swilting <john.swilting@wanadoo.fr> wrote:
> which is the best style
>
> #!/usr/bin/perl -w
#!/usr/bin/perl
> use strict;
> use warnings;
Lexical warnings are better than the -w switch.
> my %Conf = (
> XferMethod => "rsync",
> XferLogLevel => "1",
> RsyncShareName => "___1___",
> ClientNameAlias => "___2___"
> );
my %Conf = (
XferMethod => 'rsync',
XferLogLevel => '1',
RsyncShareName => '___1___',
ClientNameAlias => '___2___'
);
Double quotes give you 2 things beyond what single quotes give you,
variable interpolation and backslash escapes.
It is misleading (ie. bad style) to use double quotes when you are
not making use of one of those two things.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: 24 Aug 2007 01:12:15 GMT
From: Dan Otterburn <dan.otterburn@gmail.com>
Subject: Re: Efficiently de-duping an array
Message-Id: <46ce306f$0$21089$da0feed9@news.zen.co.uk>
On Fri, 24 Aug 2007 02:42:03 +0200, Gunnar Hjalmarsson wrote:
> Use a hash.
>
> my ( @fruits_deduped, %seen );
> while ( my $fruit = shift @fruits ) {
> push @fruits_deduped, $fruit unless $seen{$fruit}++;
> }
Many thanks. Just to clarify my understanding: this works because
"unless" binds tighter than "++" so $seen{$fruit} - on the first pass for
each different $fruit - isn't auto-vivified until *after* "unless" has
tested? i.e. it is short-hand for:
while ( my $fruit = shift @fruits ) {
if ( !$seen{$fruit} ) {
push @fruits_deduped, $fruit;
$seen{$fruit} += 1;
}
}
> See also "perldoc -q duplicate".
Apologies, I should have been able to find this without posting.
--
Dan Otterburn <dan.otterburn@gmail.com>
------------------------------
Date: Fri, 24 Aug 2007 01:31:42 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Efficiently de-duping an array
Message-Id: <slrnfcsb36.4sg.tadmc@tadmc30.sbcglobal.net>
Dan Otterburn <dan.otterburn@gmail.com> wrote:
> I have an array of a number of items, some of which are duplicates. I
> need to "de-dupe" the array,
Your Question is Asked Frequently:
perldoc -q duplicate
How can I remove duplicate elements from a list or array?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 24 Aug 2007 03:48:55 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Efficiently de-duping an array
Message-Id: <5j6rolF3t3s3bU1@mid.individual.net>
Dan Otterburn wrote:
> On Fri, 24 Aug 2007 02:42:03 +0200, Gunnar Hjalmarsson wrote:
>> Use a hash.
>>
>> my ( @fruits_deduped, %seen );
>> while ( my $fruit = shift @fruits ) {
>> push @fruits_deduped, $fruit unless $seen{$fruit}++;
>> }
>
> Many thanks. Just to clarify my understanding: this works because
> "unless" binds tighter than "++" so $seen{$fruit} - on the first pass for
> each different $fruit - isn't auto-vivified until *after* "unless" has
> tested?
Well, it's rather about what $seen{$fruit}++ _returns_; please read
about auto-increment in "perldoc perlop".
> i.e. it is short-hand for:
>
> while ( my $fruit = shift @fruits ) {
> if ( !$seen{$fruit} ) {
> push @fruits_deduped, $fruit;
> $seen{$fruit} += 1;
> }
> }
Yes, almost. (Unlike my code, your code doesn't keep incrementing the
hash values.)
>> See also "perldoc -q duplicate".
>
> Apologies, I should have been able to find this without posting.
Yes. ;-) Apology accepted.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 24 Aug 2007 02:45:52 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Efficiently de-duping an array
Message-Id: <slrnfcshfj.5ti.tadmc@tadmc30.sbcglobal.net>
Dan Otterburn <dan.otterburn@gmail.com> wrote:
> On Fri, 24 Aug 2007 02:42:03 +0200, Gunnar Hjalmarsson wrote:
>
>> Use a hash.
>>
>> my ( @fruits_deduped, %seen );
>> while ( my $fruit = shift @fruits ) {
>> push @fruits_deduped, $fruit unless $seen{$fruit}++;
>> }
>
> Many thanks. Just to clarify my understanding: this works because
> "unless" binds tighter than "++"
^^^^^^^^^^^^^
"unless" is not an operator, so talking about its precedence makes
no sense.
> each different $fruit - isn't auto-vivified until *after* "unless" has
> tested?
That part is accurate though.
> i.e. it is short-hand for:
>
> while ( my $fruit = shift @fruits ) {
> if ( !$seen{$fruit} ) {
> push @fruits_deduped, $fruit;
> $seen{$fruit} += 1;
> }
> }
>
>> See also "perldoc -q duplicate".
...then do it with a grep():
my %seen;
@fruits = grep !$seen{$_}++, @fruits;
And it even reads kind of Englishy "grep not seen fruits" :-)
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 24 Aug 2007 02:40:14 -0700
From: Dan Otterburn <dan.otterburn@gmail.com>
Subject: Re: Efficiently de-duping an array
Message-Id: <1187948414.567858.43540@z24g2000prh.googlegroups.com>
On 24 Aug, 02:31, Tad McClellan <ta...@seesig.invalid> wrote:
> Your Question is Asked Frequently:
Thanks to both of you for being gentle and taking the time to answer
(and explain the answer to) a question that should never have been
asked.
We learn by our mistakes - and I have made plenty here - so, if it is
any consolation, I have learnt more than I would have done had I found
the FAQ in the first place. I will endeavour not to make the same
mistakes twice!
------------------------------
Date: Fri, 24 Aug 2007 03:00:33 -0700
From: Bill H <bill@ts1000.us>
Subject: How safe is $0?
Message-Id: <1187949633.488453.272370@q3g2000prf.googlegroups.com>
If I use $0 to determine the name of the script that is running is it
safe to assume that it will not change within the script (as long as I
never intentionally try to change it? The way I am using it is setting
certain messages based on the the script. Somthing like this:
if ($0 eq "foo.pl")
{
$blah = "foo";
}
if ($0 eq "bar.pl")
{
$blah = "bar";
}
I tried to find this in the perldocs but didn't.
Bill H
------------------------------
Date: Fri, 24 Aug 2007 09:43:00 +0200
From: "Bond" <Bond@james.bond>
Subject: How to install WIN32::CGI on ActiveState Perl instaled on Windows XP?
Message-Id: <fam25p$no8$1@ss408.t-com.hr>
How to install WIN32::CGI on ActiveState Perl instaled on Windows XP?
------------------------------
Date: Fri, 24 Aug 2007 02:05:42 -0700
From: Bill H <bill@ts1000.us>
Subject: Is there a better way of doing this?
Message-Id: <1187946342.509055.110980@l22g2000prc.googlegroups.com>
In a script I have on a site I read all the values passed in the url
(using the GET method) into an array called $query{'foo'} where foo is
the name of the value. Though this has always worked fine I find
myself assigning them to a new variable to make it easier to recognize
them and quicker to type, for example I'll make $foo = $query{'foo'};
The question is, is there anything wrong with doing the following to
automate this process, or is there a better "perl" way of doing the
same?
foreach $temp (keys(%query))
{
eval("\$$temp = \$query{\$temp};");
}
Bill H
------------------------------
Date: Thu, 23 Aug 2007 21:59:31 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Is there a perl equivalent to the following....
Message-Id: <m2r6ltzo8s.fsf@dot-app.org>
grocery_stocker <cdalten@gmail.com> writes:
> Is there a perl equivalent to the java 'this' keyword ?
Sort of. "This" is passed to methods, but it's just the first argument,
not a keyword:
sub foo {
my ($this, $that, $the_other) = @_;
}
Perl has *many* very good tutorials about OOP in Perl. You really should
read them. From "perldoc perl":
perlboot Perl OO tutorial for beginners
perltoot Perl OO tutorial, part 1
perltooc Perl OO tutorial, part 2
perlbot Perl OO tricks and examples
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Fri, 24 Aug 2007 04:42:13 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Fri Aug 24 2007
Message-Id: <Jn9H2D.uv9@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.
Bricklayer-Templater-0.9.5
http://search.cpan.org/~zaphar/Bricklayer-Templater-0.9.5/
yet another templating system. Pure perl, highly flexible with very few dependencies.
----
Business-KontoCheck.ok-2.2
http://search.cpan.org/~michel/Business-KontoCheck.ok-2.2/
----
CGI-Application-Plugin-HelpMan-1.04
http://search.cpan.org/~leocharre/CGI-Application-Plugin-HelpMan-1.04/
man lookup and help doc for your cgi app
----
CGI-Application-Plugin-TmplInnerOuter-1.02
http://search.cpan.org/~leocharre/CGI-Application-Plugin-TmplInnerOuter-1.02/
----
CORBA-Perl-0.23
http://search.cpan.org/~perrad/CORBA-Perl-0.23/
----
Catalyst-Plugin-ConfigLoader-0.16
http://search.cpan.org/~bricas/Catalyst-Plugin-ConfigLoader-0.16/
Load config files of various types
----
Catalyst-View-BK-0.2
http://search.cpan.org/~zaphar/Catalyst-View-BK-0.2/
Catalyst View for Bricklayer::Templater
----
Catalyst-View-Templated-0.02
http://search.cpan.org/~jrockway/Catalyst-View-Templated-0.02/
generic base class for template-based views
----
Class-InsideOut-1.08
http://search.cpan.org/~dagolden/Class-InsideOut-1.08/
a safe, simple inside-out object construction kit
----
Class-Simple-0.08
http://search.cpan.org/~sullivan/Class-Simple-0.08/
Simple Object-Oriented Base Class
----
Config-Any-0.08
http://search.cpan.org/~bricas/Config-Any-0.08/
Load configuration from different file formats, transparently
----
DBI-1.59_2
http://search.cpan.org/~timb/DBI-1.59_2/
Database independent interface for Perl
----
DBI-1.59_3
http://search.cpan.org/~timb/DBI-1.59_3/
Database independent interface for Perl
----
DJabberd-Authen-LDAP-0.02
http://search.cpan.org/~urkle/DJabberd-Authen-LDAP-0.02/
An LDAP authentication module for DJabberd
----
DJabberd-EntityTime-0.03
http://search.cpan.org/~urkle/DJabberd-EntityTime-0.03/
Implements XEP-0090 and XEP-0202
----
DJabberd-RosterStorage-SQLite-Fixed-0.02
http://search.cpan.org/~urkle/DJabberd-RosterStorage-SQLite-Fixed-0.02/
a shared roster implementation for the SQLite roster storage
----
DJabberd-VCard-LDAP-0.01
http://search.cpan.org/~urkle/DJabberd-VCard-LDAP-0.01/
LDAP VCard Provider for DJabberd
----
DJabberd-VCard-LDAP-0.02
http://search.cpan.org/~urkle/DJabberd-VCard-LDAP-0.02/
LDAP VCard Provider for DJabberd
----
Data-Annotated-0.01
http://search.cpan.org/~zaphar/Data-Annotated-0.01/
Data structure Annotation module
----
Data-GUID-URLSafe-0.001
http://search.cpan.org/~rjbs/Data-GUID-URLSafe-0.001/
url-safe base64-encoded GUIDs
----
Data-ICal-TimeZone-1.23
http://search.cpan.org/~rclamp/Data-ICal-TimeZone-1.23/
timezones for Data::ICal
----
DateTime-Format-Oracle-0.03
http://search.cpan.org/~kolibrie/DateTime-Format-Oracle-0.03/
Parse and format Oracle dates and timestamps
----
Debug-Smart-0.004
http://search.cpan.org/~shibuya/Debug-Smart-0.004/
Debug messages for smart logging to the file
----
Eludia-07.08.23
http://search.cpan.org/~dmow/Eludia-07.08.23/
----
File-Mosaic-0.03
http://search.cpan.org/~boumenot/File-Mosaic-0.03/
assemble the constituent pieces of a file into a single file.
----
File-SAUCE-0.22
http://search.cpan.org/~bricas/File-SAUCE-0.22/
A library to manipulate SAUCE metadata
----
FreeMED-Relay-0.2.1
http://search.cpan.org/~rtfirefly/FreeMED-Relay-0.2.1/
----
GD-Graph-smoothlines-1.15
http://search.cpan.org/~andrei/GD-Graph-smoothlines-1.15/
----
HTML-Tested-0.27
http://search.cpan.org/~bosu/HTML-Tested-0.27/
Provides HTML widgets with the built-in means of testing.
----
HTML-WidgetValidator-0.0.1
http://search.cpan.org/~nanzou/HTML-WidgetValidator-0.0.1/
Perl framework for validating various widget HTML snipets
----
HTML-WidgetValidator-0.0.2
http://search.cpan.org/~nanzou/HTML-WidgetValidator-0.0.2/
Perl framework for validating various widget HTML snipets
----
LEOCHARRE-CLI-1.07
http://search.cpan.org/~leocharre/LEOCHARRE-CLI-1.07/
useful subs for coding cli scripts
----
LEOCHARRE-DEBUG-1.03
http://search.cpan.org/~leocharre/LEOCHARRE-DEBUG-1.03/
my default debug subroutines
----
LEOCHARRE-Dev-1.03
http://search.cpan.org/~leocharre/LEOCHARRE-Dev-1.03/
----
List-Tuples-0.02
http://search.cpan.org/~nkh/List-Tuples-0.02/
Makes tuples from lists
----
MooseX-Types-Path-Class-0.01
http://search.cpan.org/~thepler/MooseX-Types-Path-Class-0.01/
A Path::Class type library for Moose
----
Nagios-Object-0.18
http://search.cpan.org/~tobeya/Nagios-Object-0.18/
----
Nagios-Object-0.19
http://search.cpan.org/~tobeya/Nagios-Object-0.19/
----
Net-SFTP-Foreign-1.30
http://search.cpan.org/~salva/Net-SFTP-Foreign-1.30/
Secure File Transfer Protocol client
----
Objects-Collection-0.35
http://search.cpan.org/~zag/Objects-Collection-0.35/
Collections of data or objects.
----
POE-Component-Server-IRC-1.14
http://search.cpan.org/~bingos/POE-Component-Server-IRC-1.14/
A fully event-driven networkable IRC server daemon module.
----
POE-Component-Server-IRC-1.16
http://search.cpan.org/~bingos/POE-Component-Server-IRC-1.16/
A fully event-driven networkable IRC server daemon module.
----
Params-Util-0.29
http://search.cpan.org/~adamk/Params-Util-0.29/
Simple, compact and correct param-checking functions
----
Pod-Perldoc-3.14_01
http://search.cpan.org/~ferreira/Pod-Perldoc-3.14_01/
----
Pod-Perldoc-3.14_02
http://search.cpan.org/~ferreira/Pod-Perldoc-3.14_02/
----
RT-Extension-LDAPImport-0.04
http://search.cpan.org/~falcone/RT-Extension-LDAPImport-0.04/
Import Users from an LDAP store
----
Socket-Class-1.0.4
http://search.cpan.org/~chrmue/Socket-Class-1.0.4/
A class to communicate with sockets
----
Socket-Class-1.0.5
http://search.cpan.org/~chrmue/Socket-Class-1.0.5/
A class to communicate with sockets
----
Socket-Class-1.0.6
http://search.cpan.org/~chrmue/Socket-Class-1.0.6/
A class to communicate with sockets
----
String-Mutate-0.01
http://search.cpan.org/~tbone/String-Mutate-0.01/
extensible chaining of string modifiers
----
Sub-AliasedUnderscore-0.01
http://search.cpan.org/~jrockway/Sub-AliasedUnderscore-0.01/
transform a subroutine that operates on $_ into one that operates on $_[0]
----
Term-Menus-1.22
http://search.cpan.org/~reedfish/Term-Menus-1.22/
Create Powerful Terminal, Console and CMD Enviroment Menus
----
Term-Menus-1.23
http://search.cpan.org/~reedfish/Term-Menus-1.23/
Create Powerful Terminal, Console and CMD Enviroment Menus
----
Wx-0.77
http://search.cpan.org/~mbarbon/Wx-0.77/
interface to the wxWidgets cross-platform GUI toolkit
----
Wx-Demo-0.08
http://search.cpan.org/~mbarbon/Wx-Demo-0.08/
the wxPerl demo
----
Wx-Perl-Packager-0.09
http://search.cpan.org/~mdootson/Wx-Perl-Packager-0.09/
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: Thu, 23 Aug 2007 23:23:35 -0700
From: Wolfgang Hennerbichler <wogri.wogri@gmail.com>
Subject: Re: Rename Perl Process
Message-Id: <1187936615.022227.191680@x35g2000prf.googlegroups.com>
On Aug 17, 11:36 pm, j...@toerring.de (Jens Thoms Toerring) wrote:
> It seems to be the case under Linux, but there seem to be some
> other (probably mostly legacy) systems where a single fork()
> isn't enough to get rid of the controlling terminal (and where
> the daemonthus could be killed when the terminal is closed).
> To avoid such problems a double fork() traditionally has done.
> But when you're only running this on Linux where the process
> group ID differs from the process ID anyway you can forget
> about it and just fork() once.
Didn't know about that. Thanks a lot for that information, I'll stick
to it.
wogri
> Regards, Jens
> --
> \ Jens Thoms Toerring ___ j...@toerring.de
> \__________________________ http://toerring.de
------------------------------
Date: Fri, 24 Aug 2007 00:59:06 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: Script does not want to run in background ?!?
Message-Id: <4badnUBO3qVXElPbnZ2dnUVZ_v3inZ2d@comcast.com>
Benoit Lefebvre wrote:
> When I run it from the crontab or in background "&" it fails.
> chomp(@list = `ssh -q hscroot\@$hmc 'lssyscfg -r sys --all'`);
You're supposed to use `ssh -n` for that.
-n Redirects stdin from /dev/null (actually, prevents reading from
stdin). This must be used when ssh is run in the background.
------------------------------
Date: Fri, 24 Aug 2007 08:29:17 -0000
From: chinmoy.chittaranjan@gmail.com
Subject: Split strings
Message-Id: <1187944157.578555.250270@e9g2000prf.googlegroups.com>
Hi All ,
I am ver new to perl and trying to take out the last word
from a string.Like that -.E:\user\chinmoy\bsp ->
here i am trying to take out "bsp" word only from this string but i
was unable to do that . I will be appreciated if someone help me on
this matter.
Thanks
Chinmoy
------------------------------
Date: 24 Aug 2007 09:23:56 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Split strings
Message-Id: <5j7mdcF3t1i7rU1@mid.dfncis.de>
<chinmoy.chittaranjan@gmail.com> wrote in comp.lang.perl.misc:
> Hi All ,
>
> I am ver new to perl and trying to take out the last word
> from a string.Like that -.E:\user\chinmoy\bsp ->
> here i am trying to take out "bsp" word only from this string but i
> was unable to do that . I will be appreciated if someone help me on
> this matter.
To answer your question conclusively a single example isn't sufficient.
You'd have to describe the variability of the input. The way you put
the problem, one could rightly answer "$last_word = 'bsp'", because
that is the only case given. Here is one possibility:
my $last_word = ( /\w+/g)[ -1];
Anno
------------------------------
Date: Fri, 24 Aug 2007 02:56:41 -0700
From: Dan Otterburn <dan.otterburn@gmail.com>
Subject: Re: Split strings
Message-Id: <1187949401.018511.316300@x35g2000prf.googlegroups.com>
On 24 Aug, 09:29, chinmoy.chittaran...@gmail.com wrote:
> E:\user\chinmoy\bsp
That looks like a Windows file path. If you are trying to parse file
paths you might want to look at File::Basename core module.
------------------------------
Date: Fri, 24 Aug 2007 01:31:42 GMT
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Symbolic representation of logical operators
Message-Id: <slrnfcscs1.4sg.tadmc@tadmc30.sbcglobal.net>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Thu, 23 Aug 2007 14:43:37 +0100, Ben Morrow <ben@morrow.me.uk>
> wrote:
>
>>> "apples" xor "pears" ? 'TRUE' : 'FALSE'
>>
>>ITYM
>>
>> ("apples" xor "pears") ? 'TRUE' : 'FALSE'
>
> Yep, sorry!
>
>>And the OP needs to realise that to print this one must use
>>
>> print( ("apples" xor "pears") ? 'TRUE' : 'FALSE' );
>>
>>due to Perl's 'if it looks like a function it parses as a function'
>>rule.
>
> Or
>
> print +("apples" xor "pears") ? 'TRUE' : 'FALSE';
>
> which I like and confuses me less, but maybe that's just me. Come to
> think of it, I must have never used C<xor>.
The rule is a consequence of having optional parenthesis around
a function's argument list.
See also:
Message-Id: <slrn99vaqg.oij.tadmc@tadmc26.august.net>
The least confusing "fix" is to use parenthesis around the
function's argument list, even if you don't normally use them:
print(("apples" xor "pears") ? 'TRUE' : 'FALSE');
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Fri, 24 Aug 2007 09:14:00 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Symbolic representation of logical operators
Message-Id: <891tc3dj17o0jfuie46g5345aac9v5a7b8@4ax.com>
On Fri, 24 Aug 2007 01:31:42 GMT, Tad McClellan <tadmc@seesig.invalid>
wrote:
>The least confusing "fix" is to use parenthesis around the
>function's argument list, even if you don't normally use them:
>
> print(("apples" xor "pears") ? 'TRUE' : 'FALSE');
Confusion is in the eye of the beholder.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Fri, 24 Aug 2007 10:33:10 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Symbolic representation of logical operators
Message-Id: <slrnfct5u6.vd6.hjp-usenet2@zeno.hjp.at>
On 2007-08-19 20:08, Mark Hobley <markhobley@hotpop.deletethisbit.com> wrote:
> print (7 xor 2); # Empty string, I was expecting 0 (true xor true = false)
The empty string is also false, and all operators which return a "pure"
truth value (==, !=, <, >, <=, >=, !) return 1 as true and an empty
string as false. So xor is consistent with the rest of perl (although
not consistent with any other programming language I know).
The empty string returned by these operators is actually quite an
interesting piece: It is both an empty string and the number 0 at the
same time:
#!/usr/bin/perl
use warnings;
use strict;
my $x = "";
print "\$x=<$x>\n"; # Prints "<>"
my $y = $x + 5; # Warning: Argument "" isn't numeric in addition (+)
$x = !"b";
print "\$x=<$x>\n"; # Prints "<>"
$y = $x + 5; # No warning
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Fri, 24 Aug 2007 04:37:49 -0000
From: "Roycedot@gmail.com" <Roycedot@gmail.com>
Subject: Threaded Perl Processes Going to Sleep Simultaneously??? Why?
Message-Id: <1187930269.019057.140170@q3g2000prf.googlegroups.com>
Hi,
I've written a Perl program that creates 10 threads (ithreads) and
each thread operates on a different part of a large array. The large
array is just a file read in before the threads are started. Each
thread processes a chunk of the array and then prints the processed
output to a shared text file.
I run different instances of this Perl program so I can process
multiple files, but oddly all instances of this program go to sleep at
the same time and then come back at the same time. At least this is
what I see with the 'top' command in Linux.
Now, this could be a process management problem on my Linux, but I was
wondering if anyone would know any other reason? I'm 99% sure it's
not deadlock when the threads for each program write to output files
because each program writes to a different output file and yet all the
programs go to sleep at the same time.
I thought it could be a CPU limit issue on my box, but 'limit's says
CPU is unlimited and I also am now running under root with each
program reniced to -20.
Any ideas would be appreciated.
------------------------------
Date: Fri, 24 Aug 2007 01:06:52 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: UTF-8 problem
Message-Id: <U6-dndnIrekADFPbnZ2dnUVZ_u-unZ2d@comcast.com>
Todor Vachkov wrote:
> parser error : Input is not proper UTF-8, indicate encoding !
> I thought the solution would be:
>
> open(my $fh, "< :encoding(utf8)" ,'/foodir/export.xml');
It's the other way around.
open (my $fh, "< :encoding(something_that_is_not_UTF-8)", ...);
Perl is assuming the file is utf8, but it's not, therefore you need
to tell perl what encoding the file is actually using.
-Joe
------------------------------
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 789
**************************************