[29664] in Perl-Users-Digest
Perl-Users Digest, Issue: 908 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 5 14:09:41 2007
Date: Fri, 5 Oct 2007 11:09:07 -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, 5 Oct 2007 Volume: 11 Number: 908
Today's topics:
Annoying 32/64-bit inconsistency <socyl@987jk.com.invalid>
Re: command for script <ulmai@gmx.de>
Re: command for script <josef.moellers@fujitsu-siemens.com>
How to Detect a new file added to a folder and copy to <nitindutt2005@gmail.com>
Re: How to Detect a new file added to a folder and copy QoS@domain.invalid
Re: How to Detect a new file added to a folder and copy <ben@morrow.me.uk>
Re: How to Detect a new file added to a folder and copy <veatchla@yahoo.com>
Re: How to manipulate the cases of letters in a string? <zhang.xi.cn@gmail.com>
perl and eof detection <Mark.Seger@hp.com>
Re: perl and eof detection <mritty@gmail.com>
Re: perl and eof detection <dummy@example.com>
Re: perl and eof detection <Mark.Seger@hp.com>
Re: perl join on a non printable variable character ? <hjp-usenet2@hjp.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 5 Oct 2007 16:40:33 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Annoying 32/64-bit inconsistency
Message-Id: <fe5pe1$cuh$1@reader1.panix.com>
(NOTE: In the DB interactions below, I've rendered undef values as
(undef), even though in the real interaction DB would just print
a blank line. And, of course, the comments are my addition.)
On a 32-bit architecture:
DB<1> p ~0
4294967295
DB<2> p ~0 + 1
4294967296 # ~0 + 1 is stringified to an
# integer
DB<3> $x = sprintf '%s', ~0+1
DB<4> p $x
4294967296
DB<5> p $x > ~0 # numeric comparison correct,
1 # even though the integer
# represented by string $x is
# "too big" for 32 bits
DB<6> p $x == ~0 # ditto
(undef)
...but on a 64-bit architecture
DB<1> p ~0
18446744073709551615
DB<2> p ~0 + 1
1.84467440737096e+19 # first inconsistency: ~0 + 1
# stringified as a float
DB<3> $x = sprintf '%s', ~0 + 1
DB<4> p $x
1.84467440737096e+19
DB<5> $x = '18446744073709551616' # ...so we initialize $x explicitly
DB<6> p $x
18446744073709551616'
DB<8> p $x > ~0 # incorrect numeric comparison
(undef)
DB<9> p $x == ~0 # incorrect numeric comparison
1
DB<10> p $x == ~0 - ( ( 1 << 10 ) - 1 ) # incorrect numeric comparison
1
DB<11> p $x == ~0 - ( 1 << 10 ) # finally, this one is correct
(undef)
DB<12> $x = sprintf '%s', ~0
DB<13> p $x == ~0 # in contrast, all numeric
1 # comparisons with stringified ~0
# are OK
DB<14> p $x == ~0 - 1
(undef)
The 64-bit perl above was compiled with:
Platform:
osname=linux, osvers=2.6.15.7, archname=x86_64-linux-gnu-thread-multi
uname='linux crested 2.6.15.7 #1 smp sat jul 15 10:48:14 utc 2006 x86_64 gnulinux '
config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=define uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
ccversion='', gccversion='4.1.2 (Ubuntu 4.1.2-0ubuntu4)', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perllibs=-ldl -lm -lpthread -lc -lcrypt
libc=/lib/libc-2.5.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
gnulibc_version='2.5'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_64_BIT_ALL
USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_REENTRANT_API
Built under linux
Is there any way I can modify these build parameters for 64-bit to
make perl handle the string containing the number ~0 + 1 in the
same way it does under 32-bit?
TIA!
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Fri, 05 Oct 2007 15:25:48 +0200
From: Jan Pluntke <ulmai@gmx.de>
Subject: Re: command for script
Message-Id: <uk5q1ae1v.fsf@ID-18539.user.dfncis.de>
jan09876@hotmail.com writes:
> I did not use the script for a while and now I am not able to find out
> what the command was. I tried different commands but the script keep
> on saying: No such file or directory.
This text is not output anywhere in the script you pasted below, so I
believe it is the shell and not the perl program that complains
here. Do ./same.pl and /usr/bin/perl exist on your system?
Regards,
Jan
------------------------------
Date: Fri, 05 Oct 2007 15:37:09 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: command for script
Message-Id: <fe5eme$u2q$1@nntp.fujitsu-siemens.com>
jan09876@hotmail.com wrote:
> A friend wrote for me this little script so I can compare two files
> and have this output.
>=20
> Common to all files:
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Only in '1.txt':
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> Only in '2.txt':
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> I did not use the script for a while and now I am not able to find out
> what the command was. I tried different commands but the script keep
> on saying: No such file or directory.
Maybe you have transferred this script back and forth via a machine that =
uses ancient CRLF line terminators (abandoned shortly after stone=20
tablets cam out of fashion).
In that case the shebang line (the "#!/usr/bin/perl") will actually read =
"#!/usr/bin/perl<CR>" and it is highly unlikely that you'll have a=20
command of that name on your system.
Use whatever means you have at your disposal to get rid of the CR=20
characters, e.g.
tr -d '\015' < script > tmp.$$; mv tmp.$$ script
or open the file in vim (notice that it'll say "[DOS]" in the last=20
line), then type ":set fileformat=3Dunix<Enter>", then ":wq<Enter>".
Josef
--=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)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Fri, 05 Oct 2007 10:11:53 -0000
From: andy <nitindutt2005@gmail.com>
Subject: How to Detect a new file added to a folder and copy to the local machine
Message-Id: <1191579113.255421.77760@19g2000hsx.googlegroups.com>
There is a remote windows server and there is a folder named dir in
that.
Daily basis a new file is added to that perticular folder "dir". lets
say the files added will be of type abc.txt,acd.txt etc.
I want to write a perl script that will detect that new file as soon
as added to "dir" and copy to my local machine.
After that I will do some operation onto that file.
Running that script continuously can be done by using task scheduler
in windows but how can we detect the new file added to that "dir"
folder.
------------------------------
Date: Fri, 05 Oct 2007 10:25:31 GMT
From: QoS@domain.invalid
Subject: Re: How to Detect a new file added to a folder and copy to the local machine
Message-Id: <vioNi.10917$Jk2.9525@trndny03>
andy <nitindutt2005@gmail.com> wrote in message-id: <1191579113.255421.77760@19g2000hsx.googlegroups.com>
>
> There is a remote windows server and there is a folder named dir in
> that.
> Daily basis a new file is added to that perticular folder "dir". lets
> say the files added will be of type abc.txt,acd.txt etc.
>
> I want to write a perl script that will detect that new file as soon
> as added to "dir" and copy to my local machine.
> After that I will do some operation onto that file.
>
> Running that script continuously can be done by using task scheduler
> in windows but how can we detect the new file added to that "dir"
> folder.
if (-e $file) {
#the file has been detected
}
------------------------------
Date: Fri, 5 Oct 2007 15:36:51 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to Detect a new file added to a folder and copy to the local machine
Message-Id: <3puht4-7r1.ln1@osiris.mauzo.dyndns.org>
Quoth andy <nitindutt2005@gmail.com>:
> There is a remote windows server and there is a folder named dir in
> that.
> Daily basis a new file is added to that perticular folder "dir". lets
> say the files added will be of type abc.txt,acd.txt etc.
>
> I want to write a perl script that will detect that new file as soon
> as added to "dir" and copy to my local machine.
> After that I will do some operation onto that file.
>
> Running that script continuously can be done by using task scheduler
> in windows but how can we detect the new file added to that "dir"
> folder.
Either keep a list of the files you saw last time and compare to the
list of files you have now:
perldoc -f opendir
perldoc -f readdir
or, since you're on Windows, you can retrieve the creation time of a
file from the ctime member of the stat structure:
perldoc -f stat
perldoc File::stat
and check if it's new.
Ben
------------------------------
Date: Fri, 05 Oct 2007 10:16:00 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: How to Detect a new file added to a folder and copy to the local machine
Message-Id: <13gcl7c7vgv292c@news.supernews.com>
andy wrote:
> There is a remote windows server and there is a folder named dir in
> that.
> Daily basis a new file is added to that perticular folder "dir". lets
> say the files added will be of type abc.txt,acd.txt etc.
>
> I want to write a perl script that will detect that new file as soon
> as added to "dir" and copy to my local machine.
> After that I will do some operation onto that file.
>
> Running that script continuously can be done by using task scheduler
> in windows but how can we detect the new file added to that "dir"
> folder.
>
I am not sure this will work for you since you are working with a remote
server.
I keep a text file in the directory I am monitoring. This file contains
the date/time of the newest files update time stamp. I then loop
through all files in the directory and skip processing all files which
have a update time stamp, using stat(), earlier than the date/time I
saved in the text file. The date/time stamp text file is then updated
with the newest update time stamp, using stat().
--
Len
------------------------------
Date: Fri, 05 Oct 2007 15:50:16 -0000
From: xz <zhang.xi.cn@gmail.com>
Subject: Re: How to manipulate the cases of letters in a string?
Message-Id: <1191599416.035192.142980@d55g2000hsg.googlegroups.com>
On Oct 5, 3:15 am, Reinhard Pagitsch <r...@gmx.net> wrote:
> Petr Vileta wrote:
> > Jim Gibson wrote:
> >> In article <1191541667.632448.15...@g4g2000hsf.googlegroups.com>, xz
> >> <zhang.xi...@gmail.com> wrote:
>
> >>> Say, change "i LOVE this Game" into "I LOVE THIS GAME" or "i love
> >>> this game"
>
> >> perldoc -f uc
> >> perldoc -f lc
>
> > Your answer is short and to the subject, but not all perl programmers
> > use Linux. I can mention only that some of us are using ActiveState Perl
> > and we have not any perldoc.exe on our Windows PCs :-)
>
> We have perldoc.bat on our system in the \perl\bin directory.
> And we have also the HTML documentation under \perl\html.
Do you know where is this html documentation on linux?
Thanks!
> Simply open the index.html, in the left frame search for perlfunc, klick
> it and search for upper.
>
> > Maybe will be better to write some "OS independent", e.g. "look at
> > function uc()".
> > I don't know what type of documentation is on Mac.
>
> I think the same as on Win. or Unix: perldoc and/or the HTML documentation.
>
> regards,
> Reinhard
>
> --
------------------------------
Date: Fri, 05 Oct 2007 09:37:18 -0400
From: Mark Seger <Mark.Seger@hp.com>
Subject: perl and eof detection
Message-Id: <fe5emi$tmv$1@usenet01.boi.hp.com>
I'm trying to do something similar to 'tail -f', in that I want to read
a file and when new data appears read/print it. Consider the following
and you will see I simply test for eof and if there's data there
read/print and if now, test the eof again. To make this easier to
fiddle with, I added a sleep 1 between eof() calls. I also removed the
print I had after the
#!/usr/bin/perl -w
open TEST, "<test" or die;
while (1)
{
printf "EOF: %d\n", eof(TEST);
while (!eof(TEST))
{
$line=<TEST>;
print $line;
}
sleep 1;
}
I have a second script that simply open ">>test", writes a couple of
records and exist. When I run the script above, it happily reports the
contents of the file file and then starts printing "EOF: 1" as expected.
However, when I then write more to the file eof never changes!
But wait - if I comment out the 'while' line and let it continue to try
to do the reads, I get an unititialized variable on the print as
expected, but when I now print to the file eof shows up as 0 and the
script picks up the new data.
My working hypothesis is that doing the read after eof is caused the
script to reevaluate the file state. To test this theory I uncommented
the while so the script again looks as it does above but this time
inserted an extra "$line=<TEST> right before the sleep. This should
almost always fail, but now when I append to the file the eof state
correctly changes from 1 to 0 and the script begins to work again.
However, not only is this a hack, but if data were written to the file
after the loop exists and before the dummy read is executed I'd lose a
line of data.
I guess my question is what is really going on and is there a more
correct way to determine if there is data in the file before reading it?
I also discovered I could just do a stat() after the first time the file
is flushed and detect changes that way but I guess I'd like to
understand why this happening in the first place.
-mark
------------------------------
Date: Fri, 05 Oct 2007 07:25:09 -0700
From: Paul Lalli <mritty@gmail.com>
Subject: Re: perl and eof detection
Message-Id: <1191594309.019693.242210@r29g2000hsg.googlegroups.com>
On Oct 5, 9:37 am, Mark Seger <Mark.Se...@hp.com> wrote:
> I'm trying to do something similar to 'tail -f',
Have you checked the FAQ?
$ perldoc -q tail
Found in /opt2/Perl5_8_4/lib/perl5/5.8.4/pod/perlfaq5.pod
How do I do a "tail -f" in perl?
Paul Lalli
------------------------------
Date: Fri, 05 Oct 2007 14:29:37 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: perl and eof detection
Message-Id: <lTrNi.53152$nO3.50810@edtnps90>
Mark Seger wrote:
> I'm trying to do something similar to 'tail -f',
This is covered in the FAQ:
perldoc -q tail
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, 05 Oct 2007 11:25:23 -0400
From: Mark Seger <Mark.Seger@hp.com>
To: krahnj@telus.net
Subject: Re: perl and eof detection
Message-Id: <47065763.6010102@hp.com>
yes, and I also found it in faq5 as pointed out by paul in a previous
reply. it also turns out if I can get the same results by doing
something like:
while ($line=<TEST>)
{
}
instead of testing for eof at all, since doing the read on a file
already at the end-of-file also resets the eof marker. alas, I'm still
not sure which is more efficient or if it even makes much a difference.
-mark
John W. Krahn wrote:
> Mark Seger wrote:
>> I'm trying to do something similar to 'tail -f',
>
> This is covered in the FAQ:
>
> perldoc -q tail
>
>
>
> John
------------------------------
Date: Fri, 5 Oct 2007 16:58:13 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: perl join on a non printable variable character ?
Message-Id: <slrnfgck85.d4g.hjp-usenet2@zeno.hjp.at>
On 2007-10-05 04:40, Petr Vileta <stoupa@practisoft.cz> wrote:
> Jack wrote:
>> Hi I am trying to join on decimal 28, or \034 the non printable field
>> delimiter. I cant get this to work.. any help would be great ..
[...]
>> this doesnt work :
>> print OUTFILE1 join("$delimiter",$rowcounter,$_)."\n";
>> print OUTFILE1 join("\$delimiter",$rowcounter,$_)."\n";
>> print OUTFILE1 join($delimiter,$rowcounter,$_)."\n";
>> print OUTFILE1 join($$delimiter,$rowcounter,$_)."\n";
>> or any variation of above ...
>
> If you try it on Windows then you must use
> binmode OUTFILE1;
> before you write some to it.
> If you use Linux or Mac then ignore me ;-)
Ignore him anyway. binmode is for *binary* files, or - more specifically
- files which don't have a line structure. The file being written looks
like it does consist of lines, and on Windows one probably wants Windows
line endings, not bare LFs, one should not use binmode here.
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: 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 908
**************************************