[22155] in Perl-Users-Digest
Perl-Users Digest, Issue: 4376 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 10 09:05:47 2003
Date: Fri, 10 Jan 2003 06:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 10 Jan 2003 Volume: 10 Number: 4376
Today's topics:
Re: A tar utility written in Perl <mzawadzk@man.poznan.pl>
Re: A tar utility written in Perl <ericb@col.bsf.alcatel.fr>
Re: Activeperl : ppm and GD <bobx@linuxmail.org>
Re: Converting CGI to XML <usenet@tinita.de>
Re: Converting CGI to XML Andrew Lee
Re: Converting CGI to XML <barbr-en@online.no>
Re: EXCEL OLE functions <ouellmi@videotron.ca>
Re: grep == ?? (Damian James)
I need to create a .zip file, as an attachment in email <paul.g@hotpop.com>
Re: Is there a maximum length for system() or backtick <hal@thresholddigital.com>
My, our, etc. <spikey-wan@bigfoot.com>
Re: My, our, etc. <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: My, our, etc. <tassilo.parseval@post.rwth-aachen.de>
Re: parsing xml with perl --- very urgent .. help pleas Andrew Lee
Re: simple file variable question <shamrockirishbar.remove.nospam@yahoo.co.uk>
Re: simple file variable question (Anno Siegel)
Re: simple file variable question <jurgenex@hotmail.com>
Re: stucked <mats.svensson2@telia.com>
Re: stucked Andrew Lee
Re: Taint check question (Helgi Briem)
Re: These are discouraging stats to Perlistas & Pythoni (Paul Boddie)
Using substition to remove the last occurance of a word <tim@deadgoodsolutions.spam-me-and-die.com>
Re: Using substition to remove the last occurance of a <josef.moellers@fujitsu-siemens.com>
Re: Using substition to remove the last occurance of a <tassilo.parseval@post.rwth-aachen.de>
Re: Using substition to remove the last occurance of a <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: Using substition to remove the last occurance of a news@roaima.freeserve.co.uk
Re: Using substition to remove the last occurance of a (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 10 Jan 2003 09:04:39 +0100
From: Marek Zawadzki <mzawadzk@man.poznan.pl>
Subject: Re: A tar utility written in Perl
Message-Id: <Pine.GSO.4.44.0301100901160.1990-100000@rose.man.poznan.pl>
On Fri, 10 Jan 2003, pkent wrote:
> Marek Zawadzki <mzawadzk@man.poznan.pl> wrote:
> > Is there a stable tar utility written in Perl? (possibly with
> > Archive::Tar)
> > I need tar with up to 255-characters-long pathnames support,
/ ...
> Have a look at
> http://www.perl.com/language/ppt/src/tar/index.html
Thanks, but it seems that (from docs) "The current limit on file name
length is 100 characters."
> http://www.zope.org/Members/andym/TarFiles
And since this one uses Archive::Tar as well, I believe it intorduces this
limit as well.
Anybody?
-marek
------------------------------
Date: Fri, 10 Jan 2003 09:22:48 +0100
From: Eric Blanchard <ericb@col.bsf.alcatel.fr>
Subject: Re: A tar utility written in Perl
Message-Id: <3E1E82D8.7010409@col.bsf.alcatel.fr>
Marek Zawadzki wrote:
> Hello,
>
> Is there a stable tar utility written in Perl? (possibly with
> Archive::Tar)
> I need tar with up to 255-characters-long pathnames support, and GNU
> tar doesn't compile there (Cray).
> I do have Perl though...
>
Yes, Archive::Tar can be used to manage tar archive in perl.
Long time ago, I had written a little perl utility that backups
files and directories from a Win32 PC on a network drive using
.tar.gz archive. I don't know if it supports 255-characters-long
pathnames because it also uses File::Stat and File::Find to browse
the files.
But be carreful with big archives, because File::Tar builds the
archive fully in memory be fore you can write it to disk. So
keeps the archives small.
Here is the script. (Please, be indulgent, it was one of my first
perl script)
--
#!perl
#
# Backup utility
#
use File::Find;
use File::Basename;
use File::Path;
use Archive::Tar;
use Time::localtime;
# The backup root repository
$bck_root = "X:/PC/backup/" . $ENV{"COMPUTERNAME"};
$log_file = "$bck_root/backup.log";
$list_file = "$bck_root/backup_list.txt";
# Look at a file
sub bck_explore {
if (! /^.*~$/) {
if ($look_at_date) {
my @stat_res = stat ("$File::Find::name");
if ($stat_res[9] > $bck_date) {
print "$drive_letter:$File::Find::name \n";
$arch->remove("$File::Find::name");
$arch->add_files("$File::Find::name");
print LOG "ooo $drive_letter:$File::Find::name\n";
$bck_changed = 1;
}
}
else {
print "$drive_letter:$File::Find::name \n";
$arch->add_files("$File::Find::name");
print LOG "ooo $drive_letter:$File::Find::name\n";
$bck_changed = 1;
}
}
}
# Check for root backup repository
if (! -d "$bck_root") {
print "Creating backup repository $bck_root\n";
mkpath ("$bck_root", 0, 0777);
if (! -d "$bck_root") {
die ("Can't access to backup repository: $bck_root\n");
}
}
# Open the log file
open LOG, ">>$log_file" || die $!;
print LOG "-----------------------------------\n",
ctime(time()), "\n";
# Open the configuration file
if (! open LIST, "<$list_file") {
open LIST, ">$list_file" || die "Can't create configuration file:
$list_file, stopped";
print LIST "#\n",
"# Backup configuration file\n",
"#\n\n",
"# List all directories (or files) to backup\n",
"# put only one per line and use the full path with volume\n",
"# e.g: c:/local/bin\n",
"#\n\n";
close LIST;
print "Configuration file $list_file created\n",
"Fill the configuration file now to proceed backup\n";
exit (0);
}
while (<LIST>) {
# Skip comments and blank lines
next if /^\s*#/;
next if /^\s*$/;
chomp;
$bck_src = "$_";
$bck_src =~ tr/A-Z/a-z/;
if (! -e "$bck_src") {
print STDERR "Can't find $bck_src\n";
print LOG "Can't find $bck_src\n";
next;
}
# Extract drive letter and name of directory to backup
($drive_letter, $arch_base) = $bck_src =~ m,(.):/(.*),;
$arch_name = $arch_base;
$arch_name =~ tr/\/ /__/;
# Build full archive name
$bck_archive = $bck_root . "/" . $drive_letter . "/" .
$arch_name . ".tar.gz";
# Check for already existing archive
if (-e "$bck_archive") {
# Get the last modification date of this archive
my @stat_res = stat ("$bck_archive");
$bck_date = $stat_res[9];
$look_at_date = 1;
}
else {
# The archive doesn't exist yet
$look_at_date = 0;
print LOG "New archive creation: $bck_archive\n";
# Look at the path for this new archive
$dir = dirname ("$bck_archive");
if (! -d "$dir") {
# Create the path for the new archive
print "Creating directory $dir\n";
mkpath ("$dir", 0, 0777);
}
}
chdir("$drive_letter" . ":/");
# Create a GZiped tar archive in memory
$arch = Archive::Tar->new($bck_archive, 1);
print "Exploring $bck_src ...\n";
$bck_changed = 0;
# traverse directory to backup
print LOG "Exploring $bck_src:\n";
find (\&bck_explore, "/" . "$arch_base");
# Save the archive
if ($bck_changed) {
print "Writing $bck_archive ...\n";
$arch->write ("$bck_archive", 1);
print LOG "*** Writing to archive $bck_archive\n";
}
else {
print LOG "*** Nothing changed in $bck_src\n";
}
}
close LIST;
close LOG;
# EOF
# Local Variables:
# mode: Perl
# tab-width: 8
# End:
------------------------------
Date: Fri, 10 Jan 2003 10:49:14 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: Activeperl : ppm and GD
Message-Id: <KyxT9.5325$Fj2.3095087@news2.news.adelphia.net>
"Randy Kobes" <randy@theoryx5.uwinnipeg.ca> wrote in message
news:EqqT9.18510$7_.75007@news1.mts.net...
> "Bob X" <bobx@linuxmail.org> wrote in
> message news:v9mT9.5026$Fj2.2959901@news2.news.adelphia.net...
> [ ... ]
> >
> > Randy,
> >
> > Theoryx used to have the Storable.ppd file as well. I didn't notice it
> gone
> > until I tried to install the PlRPC.ppd and it errored out looking for
> > Storable at the Log4perl site. Do you know of another place to find it?
> >
> > Bob
>
> I just put up a Storable ppm package under
> http://theoryx5.uwinnipeg.ca/ppms/
> (for ActivePerl 8xx builds).
>
> best regards,
> randy kobes
>
>
THANKS!
Bob
------------------------------
Date: 10 Jan 2003 11:17:27 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Converting CGI to XML
Message-Id: <tinh8hxw5$11q$tina@news01.tinita.de>
Keith R. <kmrob72@comcast.net> wrote:
> Does anybody know if it's possible to convert CGI to XML?
s/CGI/XML/;
SCNR =)
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Fri, 10 Jan 2003 06:26:45 -0500
From: Andrew Lee
Subject: Re: Converting CGI to XML
Message-Id: <rebt1vscuif5f7gogg1693lkns6s4s0oit@4ax.com>
On Thu, 09 Jan 2003 22:39:11 +0000, David Dorward <dorward@yahoo.com>
wrote:
>Keith R. wrote:
>> Does anybody know if it's possible to convert CGI to XML? I've seen a
>> few things on the web regarding this but haven't found anything
>> descriptive enough. Please help. Thanks.
>
>CGI is a means for a webserver to recieve generated content from programs.
>XML is a language for defining mark up lanugages.
>Converting between them is rather like converting between oxygen and the
>colour pink.
LOL
------------------------------
Date: Fri, 10 Jan 2003 13:18:03 +0100
From: Kåre Olai Lindbach <barbr-en@online.no>
Subject: Re: Converting CGI to XML
Message-Id: <vdet1vo1kgd9nm59clk6en5hit2ef1jauj@4ax.com>
On 10 Jan 2003 11:17:27 GMT, Tina Mueller <usenet@tinita.de> wrote:
>Keith R. <kmrob72@comcast.net> wrote:
>> Does anybody know if it's possible to convert CGI to XML?
>
>s/CGI/XML/;
>
>SCNR =)
$Tina =~ s/SMOKER/NON_SMOKER/;
SCNR ;-)
--
mvh/Regards
Kåre Olai Lindbach
------------------------------
Date: Fri, 10 Jan 2003 06:47:50 -0500
From: "Michele Ouellet" <ouellmi@videotron.ca>
Subject: Re: EXCEL OLE functions
Message-Id: <3pyT9.20969$3u5.144829@weber.videotron.net>
Hi!
Have you tried using Excel Help? Choosing:
Programming Information | Microsoft Excel Visual Basic Reference | Microsoft
Excel Objects, for instance, will help orient your work. Also, playing with
macros should go a long way.
Good Luck,
Michele Ouellet.
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:90oT9.39650$1c.5375@nwrddc01.gnilink.net...
> Javier Pérez Montes wrote:
> > I need to access with Perl the OLE functions of Excel, I have few
> > examples but I need a more complete source or manual.
>
> perldoc Win32::OLE
>
> jue
>
>
------------------------------
Date: 10 Jan 2003 05:41:18 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: grep == ??
Message-Id: <slrnb1sn7t.3o7.damian@puma.qimr.edu.au>
On Thu, 9 Jan 2003 22:09:51 -0600, Tad McClellan said:
>monkeys paw <fm_duendeBASURA@yahoo.com> wrote:
>...
>> I guess the source of my confusion
>> is why is "$_ == $sched_rundate" in there? Why not just:
>>
>> grep $sched_rundate, @dates
>
>
>Because then it would be testing for some other condition. :-)
>
>It would be testing if any of the list elements are "true",
>rather than if they are equal to some particular value.
?? It looks to me like it is testing whether $sched_rundate is true,
and doing it scalar @dates times. I suspect the OP is after the synatx
of the *nix grep, which would be more something like:
grep /$sched_rundate/, @dates;
But that checks whether any item in @dates *contains* $sched_rundate,
not whether there is an item in @dates that is numerically equal to
$sched_rundate. Note that this last statement is equivalent to:
grep $_ =~ m/$sched_rundate/, @dates;
See the perlfunc entry for grep(), and the perlvar entry for $_.
--damian
------------------------------
Date: Fri, 10 Jan 2003 10:40:24 -0000
From: "Grimbo" <paul.g@hotpop.com>
Subject: I need to create a .zip file, as an attachment in email! is there an easy way to do this?
Message-Id: <soxT9.8668$q67.3679@news-binary.blueyonder.co.uk>
The process is:
1. Receive $string from form! (Remain in memory if pos small file)
2. Convert $string to .zip file format (windows etc.)!
3. Convert .zip file into format $string2 acceptable as attachment to an
email (text)
4. Send attachment $string2 and email content.
I have all the other pieces of code sorted out but cannot think of a way to
shorten this process i.e. the string from the form input (1) to the output
string acceptable in text format as an attachment (3)
Any help on this would be appreciated
paul
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.435 / Virus Database: 244 - Release Date: 30/12/2002
------------------------------
Date: Fri, 10 Jan 2003 05:08:30 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Is there a maximum length for system() or backtick commands?
Message-Id: <izsT9.629940$%m4.203093@rwcrnsc52.ops.asp.att.net>
Benjamin Goldberg wrote:
> Hal Vaughan wrote:
>>
>> I've been testing Bash for maximum command line lengths (and trying to
>> find a limit in the man page) and can't find any.
>
> The limit is not due to the shell, but due to the underlying syscall --
> I would suggest you do 'man exec' from your commandline, and scroll down
> to where it mentions ARG_MAX.
It never occured to me that the limit would be on the number of args, NOT on
the line length. Thanks for pointing that out.
man exec gives me the short bash command help -- the one that lists bash
built-ins. Doing 'man bash|grep ARG_MAX' yeilds nothing.
> [snip]
>> Is there a maximum length I can make $command without problems? I can
>> easily see sending 400 (or even 500) files to the printer this way.
>> I'd rather do it in one command (for various reasons), then breaking
>> it down by limiting each command to only a certain number of files.
>
> How about:
> open( FILENAMES_TO_PRINTER, "| xargs lp");
> foreach my $file (@files) {
> print FILENAMES_TO_PRINTER $file, "\n";
> }
> close FILENAMES_TO_PRINTER;
> [untested]
>
> This does have the effect of breaking it down, and limiting each command
> to only a certain number of files, but the 'xargs' program knows what
> ARG_MAX is, and puts on each commandline the *maximum* number of files.
That might be a BIG help. Does it start sending out commands WHILE the loop
is still running, or will it wait until I close the file handle? One of my
concerns is that I very likely might be printing OpenOffice.org files,
instead of postscript, and OOo can take time (10 seconds on my 500 Mhz on
Linux) to load for a command like "oowriter -p file1 file2...." and the
purpose of sending multiple commands is to eliminate the pause between
printout sheets. I figure if one line can hold 15 args, that pause will be
"hidden" by the time it takes to print out the pages. (I still am not sure
if I'll be using lp or oowriter.)
> The only alternative I can think of is to concatenate all of those files
> into a single file (using pr to add headers and footers to each page),
> and send it to lpr. Something like:
>
> open( FILENAMES_TO_PRINTER, "| xargs pr | lp -");
> foreach my $file (@files) {
> print FILENAMES_TO_PRINTER $file, "\n";
> }
> close FILENAMES_TO_PRINTER;
> [untested]
I thought of that too. If I'm using text files, that's what I might do, but
if I am using OOo or Abiword files, it won't work easily.
Thanks for the help/info/suggestions. It's a big help!
Hal
------------------------------
Date: Fri, 10 Jan 2003 13:10:10 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: My, our, etc.
Message-Id: <avmgp5$jhd$1@newshost.mot.com>
Well, I've had a slapping for using our when I define my variables, but I
don't understand why.
I always use strict and warnings (Win32), so if I don't use our or my, I get
complaints.
I defined some Tk widgets in my script, like this, with no errors:
my $entry = $frame -> Entry () -> pack ();
However, when I decided to try some entry validation, this gave me errors:
my $entry = $frame -> Entry (
-validatecommand => \&valid_routine,
-invalidcommand => sub {
print "invalid entry, try again\n";
$entry -> focus;}
) -> pack ();
It carried on complaining when I replaced my with our, and the only way I
found to stop the complaints was to drop the my/our altogether, and add the
line
our $entry;
before I defined the widget.
So, why should I stop using our to predifine variables, when I get no
trouble doing it that way, but other ways seem to get me into trouble with
use strict?
Thanks.
R.
------------------------------
Date: Fri, 10 Jan 2003 14:36:29 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: My, our, etc.
Message-Id: <newscache$u43i8h$cb7$1@news.emea.compuware.com>
Richard S Beckett wrote (Friday 10 January 2003 14:10):
> Well, I've had a slapping for using our when I define my variables, but I
> don't understand why.
>
> I always use strict and warnings (Win32), so if I don't use our or my, I
> get complaints.
That is good.
> I defined some Tk widgets in my script, like this, with no errors:
>
> my $entry = $frame -> Entry () -> pack ();
>
> However, when I decided to try some entry validation, this gave me errors:
>
> my $entry = $frame -> Entry (
> -validatecommand => \&valid_routine,
> -invalidcommand => sub {
> print "invalid entry, try again\n";
> $entry -> focus;}
> ) -> pack ();
>
> It carried on complaining
What were the warnings/errors? Commenting on them without seeing them is
hard to do.
> when I replaced my with our, and the only way I
> found to stop the complaints was to drop the my/our altogether, and add
> the line
> our $entry;
> before I defined the widget.
>
> So, why should I stop using our to predifine variables, when I get no
> trouble doing it that way, but other ways seem to get me into trouble with
> use strict?
Using strict doesn't get you into trouble. It reports you are already in
trouble. Disregarding warnings from strict is a sure way to end up with
faulty scripts. That is just a matter of time. You will get bitten.
So again, accept as much help as you possibly can:
use strict;
use warnings;
use diagnostics;
> Thanks.
>
> R.
HTH
--
KP
------------------------------
Date: 10 Jan 2003 13:49:41 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: My, our, etc.
Message-Id: <avmj1l$kef$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Richard S Beckett:
> Well, I've had a slapping for using our when I define my variables, but I
> don't understand why.
>
> I always use strict and warnings (Win32), so if I don't use our or my, I get
> complaints.
>
> I defined some Tk widgets in my script, like this, with no errors:
>
> my $entry = $frame -> Entry () -> pack ();
>
> However, when I decided to try some entry validation, this gave me errors:
>
> my $entry = $frame -> Entry (
> -validatecommand => \&valid_routine,
> -invalidcommand => sub {
> print "invalid entry, try again\n";
> $entry -> focus;}
> ) -> pack ();
>
> It carried on complaining when I replaced my with our, and the only way I
> found to stop the complaints was to drop the my/our altogether, and add the
> line
> our $entry;
> before I defined the widget.
Adding 'my $entry' on top would have also worked, I guess.
If you have something like:
my $var = ... $var ...;
you actually have two different variables: the lexical $var on the left
side and the global variable $var ($main::var actually) on the right
hand side. Basically, you can't use the lexical in the same statement
where you declare it using my(). The most obvious workaround for your
code would be:
my $entry;
$entry = $frame -> Entry (
-validatecommand => \&valid_routine,
-invalidcommand => sub {
print "invalid entry, try again\n";
$entry->focus }
},
)->pack;
thus turning the declaration and the assignment into two statements. By
the time you assign something to $entry it has already been made a
lexical and perl knows about it.
> So, why should I stop using our to predifine variables, when I get no
> trouble doing it that way, but other ways seem to get me into trouble with
> use strict?
Because what you do is a fix that works without your knowing why. :-)
With the above technique you wont have problems using strictures without
relying on global variables (as they are declared by our()).
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Fri, 10 Jan 2003 05:51:07 -0500
From: Andrew Lee
Subject: Re: parsing xml with perl --- very urgent .. help please
Message-Id: <e39t1vo2ttuu6dirko3t3a42d3fpt22maq@4ax.com>
On Thu, 9 Jan 2003 21:47:15 -0600, tadmc@augustmail.com (Tad
McClellan) wrote:
>reddy <vanikandoori@yahoo.com> wrote:
>
[snip]
>
>> # initialize the parser
>> my $parser = XML::Parser->new( Handlers =>
>
>
>
>There is almost always a better way than using XML::Parser nowadays.
>
>With data as simple as yours, there is a much much better way...
>
>
Tad, I am curious, why do you say there is almost always a better way
than the XML::Parser module. I don't know the module at all but was
discussing RPC across sockets using XML. Are there better modules to
be had?
Thanks
------------------------------
Date: Fri, 10 Jan 2003 12:46:22 +0100
From: "Walter Mitty" <shamrockirishbar.remove.nospam@yahoo.co.uk>
Subject: Re: simple file variable question
Message-Id: <avmbqe$8j2$06$1@news.t-online.com>
"Brian McCauley" <nobull@mail.com> schrieb im Newsbeitrag
news:u9vg0ymday.fsf@wcl-l.bham.ac.uk...
> "Walter Mitty" <shamrockirishbar.remove.nospam@yahoo.co.uk> writes:
>
> > (I hope!)
> >
> > I have downloaded a perl script which I have embedded in a page as a
> > hyperlink to the script file. This script references a data file using a
> > perl variable name. When I test it though, if the perl script is
executed
> > from a page in a different directory it doesn't find the data file it
needs
> > (both perl script and data file are in my root web directory). How to I
> > specifiy the filename to be absolutely in my root directory?
>
> You represent an abolute filename "/something/like/this". This, of
> course, has nothing to do with Perl.
>
> Of you want to find the absolute path of your document root then this
> information is available under CGI in $ENV{DOCUMENT_ROOT}. This, of
> course, has nothing to do with Perl.
>
> If you want the directory from which the script was loaded this can be
> derived from $ENV{SCRIPT_FILENAME}. This, of course, has nothing to do
> with Perl.
>
> Of course, inside your server document hierachy is a pathologically
> bad place to keep data files unless you actually _want_ them to be
> downloadable. This, of course, has nothing to do with Perl.
>
> BTW: Did I mention that none this has anything to do with Perl.
>
You did. I thought this script was Perl. it has a .pl extension. I was told
it's Perl. Different languages have different ways of representing a file
location. Excuse my ignorance your majesty.
------------------------------
Date: 10 Jan 2003 13:04:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: simple file variable question
Message-Id: <avmgc0$9pj$1@mamenchi.zrz.TU-Berlin.DE>
Walter Mitty <shamrockirishbar.remove.nospam@yahoo.co.uk> wrote in comp.lang.perl.misc:
> "Brian McCauley" <nobull@mail.com> schrieb im Newsbeitrag
[...]
> > BTW: Did I mention that none this has anything to do with Perl.
> >
>
> You did. I thought this script was Perl. it has a .pl extension. I was told
> it's Perl. Different languages have different ways of representing a file
> location. Excuse my ignorance your majesty.
Please name a language that determines the way a file location is
represented. Every language I have seen provides a way to specify
file names according to the OS it is running on, so as to make this
*independent* of the particular language.
Your question has nothing to do with Perl.
Anno
------------------------------
Date: Fri, 10 Jan 2003 13:07:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: simple file variable question
Message-Id: <DAzT9.15689$gb.10585@nwrddc03.gnilink.net>
Walter Mitty wrote:
> You did. I thought this script was Perl. it has a .pl extension. I
> was told it's Perl. Different languages have different ways of
> representing a file location.
They do? I know that different operating systems use different methods to
represent a file location. But I wasn't aware that you write a file path in
a different way in different programming languages. Do you have an example?
jue
------------------------------
Date: Fri, 10 Jan 2003 09:25:59 GMT
From: "Mats" <mats.svensson2@telia.com>
Subject: Re: stucked
Message-Id: <20030110.102613.1139901474.2996@telia.com>
Thanx Martien
You gave an idea to me, using both back and forward reference on the
posts.
And you are right, this is not a specific perl-problem, but you discuss
algoritms also here, or?
/Regards from Mats
> On Fri, 10 Jan 2003 01:34:19 GMT,
> Mats <mats.svensson2@telia.com> wrote:
>> Hi
>>
>> I'm building a threaded messageboard with perl and mysql but I can't
>> come up with an algoritm for threading the messages, I have looked over
>> the net to find something that could lead me in the right direction but
>> can't find anything. Isn't this a common task in cgi-programming?
>
> Normally what you would do is make sure that each message has a unique
> id, and that each followup refers to at least the message it follow up
> to, and possibly to its parents as well.
>
> This is for example how Usenet works.
>
> Of course, this really has nothing to do with Perl at all, since the
> question and the answer would have been the same if you were writing in
> C, java or befunge.
>
> Martien
------------------------------
Date: Fri, 10 Jan 2003 06:23:34 -0500
From: Andrew Lee
Subject: Re: stucked
Message-Id: <jg9t1voe3p02op529e0t8re8210sjfu6eg@4ax.com>
On Fri, 10 Jan 2003 01:34:19 GMT, "Mats" <mats.svensson2@telia.com>
wrote:
>Hi
>
>I'm building a threaded messageboard with perl and mysql but I can't come
>up with an algoritm for threading the messages, I have looked over the
>net to find something that could lead me in the right direction but can't
>find anything. Isn't this a common task in cgi-programming?
>
It may be. It's not really a Perl problem, though.
I've dealt with parent/child relationships in databases via tree
representations (see Joe Celko's book "SQL for Smarties"). That's a
nice data driven approach. If you are thinking in Perl, look at
perldoc perldsc "More Elaborate Records." If you represent a message
like :
my $msg = {
TEXT => $body,
ID => $unique_id,
DATE => $post_date,
AUTHOR => $authors{$some_id},
RECORD => $filename,
PARENT => $msg_ref,
CHILDREN => [ @msg_refs ],
PRINT => \&print_code,
PURGE => \&del_code,
...
}
You see that as long as you can generate unique id's you can nail down
the threading.
Of course there is more than one way to so it -- I am just tossing out
an idea. I'd opt for the database driven approach myself.
Take a look at
http://searchdatabase.techtarget.com/tip/1,289483,sid13_gci537290,00.html
------------------------------
Date: Fri, 10 Jan 2003 10:57:45 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Taint check question
Message-Id: <3e1ea690.546724117@news.cis.dfn.de>
On Thu, 09 Jan 2003 21:40:17 +0100, "Harald H.-J. Bongartz"
<bongie@gmx.net> wrote:
>Simon Andrews wrote:
>> Copy your executable from wherever your reference copy is to your
>> current directory
>> use File::Copy;
>> copy ('/usr/bin/oldprog','./oldprog') || die "Can't copy file $!";
>
>I would prefer link()ing the program to the new directory, if possible,
>not copying it.
perldoc -f link
link $file, $link
or die "Cannot create link $link to $file:$!\n!";
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: 10 Jan 2003 04:51:38 -0800
From: paul@boddie.net (Paul Boddie)
Subject: Re: These are discouraging stats to Perlistas & Pythonistas...
Message-Id: <23891c90.0301100451.310246d5@posting.google.com>
jacob@cd.chalmers.se (Jacob Hallen) wrote in message news:<avfkpp$a7n$1@nyheter.chalmers.se>...
>
> An interesting thought is wether the 55 Python programmers will produce
> more useful applications than the 2037 VB programmers.
It gets even more interesting if you take monkeys and typewriters into
consideration.
Paul
------------------------------
Date: Fri, 10 Jan 2003 10:59:59 -0000
From: "tim" <tim@deadgoodsolutions.spam-me-and-die.com>
Subject: Using substition to remove the last occurance of a word
Message-Id: <1042196415.13163.0@doris.uk.clara.net>
Hi,
I have a string that contains multiple lines and I want to remove just the
last occurance of a particular word. Using subsituition I can either remove
the first or all of them, but can't see how to just remove the last one.
Can anyone shed some light on this for me please?
------------------------------
Date: Fri, 10 Jan 2003 14:00:32 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Using substition to remove the last occurance of a word
Message-Id: <3E1EC3F0.FCF15C30@fujitsu-siemens.com>
tim wrote:
> =
> Hi,
> =
> I have a string that contains multiple lines and I want to remove just =
the
> last occurance of a particular word. Using subsituition I can either r=
emove
> the first or all of them, but can't see how to just remove the last one=
=2E
> =
> Can anyone shed some light on this for me please?
TMTOWTDI, how about
@segments =3D split(/\b$word\b/, $sentence);
if ($#segments !=3D 0) {
my $last =3D pop(@segments);
$segments[$#segments] .=3D $last;
$sentence =3D join($word, @segments);
}
Note the use of \b to catch while words only.
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: 10 Jan 2003 13:13:01 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Using substition to remove the last occurance of a word
Message-Id: <avmgst$hr9$1@nets3.rz.RWTH-Aachen.DE>
Also sprach tim:
> I have a string that contains multiple lines and I want to remove just the
> last occurance of a particular word. Using subsituition I can either remove
> the first or all of them, but can't see how to just remove the last one.
>
> Can anyone shed some light on this for me please?
There are several ways. Using a regex, you need a negative look-ahead
assertion:
s/$word(?!.*$word)//s;
The left side will only match if $word is not followed by /.*$word/.
Since this assertion is zero-length, nothing following $word is
replaced.
Another way would be using substr:
substr $string, rindex($string, $word), lenth($word), "";
but this is error-prone. If you want to remove the last 'foo' word but
your string contains 'foobar' behind the last occurance of 'foo', the
above will turn 'foobar' into 'bar' instead of removing the last word
'foo'.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Fri, 10 Jan 2003 14:12:45 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Using substition to remove the last occurance of a word
Message-Id: <newscache$912i8h$2b7$1@news.emea.compuware.com>
tim wrote (Friday 10 January 2003 11:59):
> Hi,
>
> I have a string that contains multiple lines and I want to remove just the
> last occurance of a particular word. Using subsituition I can either
> remove the first or all of them, but can't see how to just remove the last
> one.
Read "perldoc perlop" and in particular"Regexp Quote-Like Operators":
use strict;
use warnings;
my $string = "Foo\nBar\nBar\nFoo\nBar\nFoo\nFoo\n";
my $target = "Bar";
$string =~ /^(.*)($target)(.*)$/s;
print "-" x 20,"\n";
print "[$1]\n";
print "-" x 20,"\n";
print "[$2]\n";
print "-" x 20,"\n";
print "[$3]\n";
HTH
--
KP
------------------------------
Date: Fri, 10 Jan 2003 13:39:54 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: Using substition to remove the last occurance of a word
Message-Id: <afimva.cbq.ln@moldev.cmagroup.co.uk>
tim <tim@deadgoodsolutions.spam-me-and-die.com> wrote:
> I have a string that contains multiple lines and I want to remove just the
> last occurance of a particular word. Using subsituition I can either remove
> the first or all of them, but can't see how to just remove the last one.
my $phrase = 'Remove the last occurrence of the word the from this sentence';
my $word = 'the';
my $p = reverse $phrase;
my $w = reverse $word;
$p =~ s/\s*\b$w\b\s*/ /; # Also strip its whitespace
my $result = reverse $p;
print "$result\n";
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: 10 Jan 2003 13:46:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Using substition to remove the last occurance of a word
Message-Id: <avmird$lc1$1@mamenchi.zrz.TU-Berlin.DE>
Josef Möllers <josef.moellers@fujitsu-siemens.com> wrote in comp.lang.perl.misc:
> tim wrote:
> >
> > Hi,
> >
> > I have a string that contains multiple lines and I want to remove just the
> > last occurance of a particular word. Using subsituition I can either remove
> > the first or all of them, but can't see how to just remove the last one.
> >
> > Can anyone shed some light on this for me please?
>
> TMTOWTDI, how about
>
> @segments = split(/\b$word\b/, $sentence);
> if ($#segments != 0) {
> my $last = pop(@segments);
> $segments[$#segments] .= $last;
> $sentence = join($word, @segments);
> }
>
> Note the use of \b to catch while words only.
Very considerate.
A minor problem with the solution is that it leaves the surrounding
delimiters in the text, so there will be two blanks where the word was.
A more serious one is that it doesn't work right when $word is the
last word in $sentence. It will then delete the last occurrence and
the next-to-last one.
I'd probably use /\b$word\b/g and refer to the @- array to find the
last occurrence:
if ( () = $sentence =~ /\b$word\b/g ) {
substr( $sentence, $-[ -1], length $word) = '';
}
This doesn't bother about additional blanks either. The "() =" in the
condition is there to put the match in list context.
Another approach might use rindex(), though it's hard to do the
equivalent of surrounding the word with \b this way.
One might also reverse() $sentence and $word, delete the first
occurrence and reverse $sentence again.
Anno
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4376
***************************************