[24388] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6576 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 18 06:05:46 2004

Date: Tue, 18 May 2004 03:05: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           Tue, 18 May 2004     Volume: 10 Number: 6576

Today's topics:
        Can't build GD.pm on Solaris8 <jure.simsic@mobitel.si>
    Re: Easier test for "regular file"? <usenet@morrow.me.uk>
    Re: Global variables in mod_perl <Joe.Smith@inwap.com>
    Re: Global variables in mod_perl <noreply@gunnar.cc>
        How to get a Color Display <georgekinley@hotmail.com>
    Re: How to get a Color Display <ThomasKratz@REMOVEwebCAPS.de>
        installing modules on shared server continued <wunkalunka@elvis.com>
    Re: installing modules on shared server continued <usenet@morrow.me.uk>
    Re: installing modules on shared server continued <wunkalunka@elvis.com>
    Re: installing modules on shared server continued <noreply@gunnar.cc>
    Re: installing modules on shared server continued <usenet@morrow.me.uk>
    Re: installing modules on shared server continued <noreply@gunnar.cc>
        LWP with Crypt::SSLeay or Net::SSLeay with OpenSSL v0.9 <first_dot_news_dot_20_dot_taylorcc@spameater_.org>
    Re: Net::DNS <bob.lockie.NOSPAM@mail.com>
        Parsing a text file..... (John Smith)
    Re: Parsing a text file..... <usenet@morrow.me.uk>
    Re: Parsing a text file..... <krahnj@acm.org>
    Re: Parsing a text file..... <josef.moellers@fujitsu-siemens.com>
        perlmagick and image size <rosszNOSPAM@vamos-wentworth.org>
    Re: perlmagick and image size <gnari@simnet.is>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 18 May 2004 07:31:45 GMT
From: "Jure Simsic" <jure.simsic@mobitel.si>
Subject: Can't build GD.pm on Solaris8
Message-Id: <BZiqc.3241$37.393054@news.siol.net>

I cant't build GD-1.41 on Solaris 8. When building, I get:
gcc -B/usr/ccs/bin/ -c  -I/usr/local/include -I/usr/local/include/gd2
-fno-strict-aliasing
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O
-DVERSION=\"1.41\" -DX
S_VERSION=\"1.41\" -fPIC
"-I/usr/local/lib/perl5/5.8.3/sun4-solaris/CORE"  -DHAVE_JPEG -DHA
VE_TTF -DHAVE_XPM GD.c
GD.xs: In function `newDynamicCtx':
GD.xs:342: structure has no member named `free'
GD.xs: In function `XS_GD__Image_newFromPngData':
GD.xs:395: structure has no member named `free'
GD.xs: In function `XS_GD__Image_newFromGdData':
GD.xs:412: structure has no member named `free'
GD.xs: In function `XS_GD__Image_newFromGd2Data':
GD.xs:429: structure has no member named `free'
GD.xs: In function `XS_GD__Image_newFromJpegData':
GD.xs:472: structure has no member named `free'
GD.xs: In function `XS_GD__Image_newFromWBMPData':
GD.xs:494: structure has no member named `free'
make: *** [GD.o] Error 1


I'm using 
- v5.8.3 built for sun4-solaris
- gcc version 3.2.3
- libgd gd-2.0.23 with jpeg & png & freetype


I've asked my friend Google about this and the only time this has
happened was, when someone tried to compile GD.pm with old libgd (pre
1.8)..

It's true that I had libgd 1.8.4 before but have rebuilt libgd anew
(for couple of times) and it's 2.0.23 now (or should be at least)

Any hints how to get to the bottom of this

Tnx
Jure


------------------------------

Date: Tue, 18 May 2004 02:03:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Easier test for "regular file"?
Message-Id: <c8bqu7$f96$1@wisteria.csv.warwick.ac.uk>


Quoth bill <please_post@nomail.edu>:
> 
> I'm writing a package that needs to interact with cvs.  For what
> I want to do I need the ability to determine whether or not a file
> is considered "regular" by cvs.
>
>   sub is_regular {
>     local $_ = shift;  # argument is a filename
> 
>     # brute-force elimination
>     !(-b||-c||-d||-l||-p||-S||-t);
>   }
> 
> (Note: having is_regular return -f --instead of the above--would
> be no good; for example -f evaluates to 1 if $_ is the name of a
> symlink.)

Yes, but that is the only case, so

not -l and -f _;

is what you want (the tests must come in this order: -f and not -l _
would do a stat(2) not an lstat(2) and thus not catch symlinks).

OTOH, are you sure that a symlink to a regular file is unacceptable:
what does cvs do about following symlinks?

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


------------------------------

Date: Tue, 18 May 2004 09:46:14 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Global variables in mod_perl
Message-Id: <GXkqc.18981$gr.1575022@attbi_s52>

Gunnar Hjalmarsson wrote:

> Glenn Jackman wrote:
> 
>> http://perl.apache.org/docs/2.0/user/coding/coding.html#Shared_Variables
> 
> Hmm.. Mark convinced me that it was caused by multiple processes rather 
> than threads. Can you please explain?

Some operating systems implement threads in a way that they look like
processes.  The value $$ is different in each thread.
	-Joe


------------------------------

Date: Tue, 18 May 2004 11:56:23 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Global variables in mod_perl
Message-Id: <2gu4u1F6o8pqU1@uni-berlin.de>

Joe Smith wrote:
> Gunnar Hjalmarsson wrote:
>> Glenn Jackman wrote:
>>> http://perl.apache.org/docs/2.0/user/coding/coding.html#Shared_Variables
>> 
>> Hmm.. Mark convinced me that it was caused by multiple processes
>> rather than threads. Can you please explain?
> 
> Some operating systems implement threads in a way that they look
> like processes.  The value $$ is different in each thread.

Okay, thanks. Guess I need to read up on both processes and threads...

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Tue, 18 May 2004 07:06:33 GMT
From: "George Kinley" <georgekinley@hotmail.com>
Subject: How to get a Color Display
Message-Id: <ZBiqc.16609$k4.335168@news1.nokia.com>

Hi,
I am using/working on Win2K, I run my scripts on cmd.exe ,
I want to change attributes of my print statements in color ,

If I use code from perlfaq8.pod

use Term::ANSIColor;
print color("red"), "Stop!\n", color("reset");
print color("green"), "Go!\n", color("reset");


The output I get is

?[31mStop!
?[0m?[32mGo!
?[0m

I have gut feeling its a basic query , but what is wrong
-g




------------------------------

Date: Tue, 18 May 2004 11:36:56 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: How to get a Color Display
Message-Id: <40a9dab2.0@juno.wiesbaden.netsurf.de>

George Kinley wrote:

> Hi,
> I am using/working on Win2K, I run my scripts on cmd.exe ,
> I want to change attributes of my print statements in color ,
> 
> If I use code from perlfaq8.pod
> 
> use Term::ANSIColor;
> print color("red"), "Stop!\n", color("reset");
> print color("green"), "Go!\n", color("reset");
> 
> 
> The output I get is
> 
> ?[31mStop!
> ?[0m?[32mGo!
> ?[0m
> 
> I have gut feeling its a basic query , but what is wrong

Your command interpreter (cmd.exe) needs to have ansi.sys loaded (just 
like under plain old DOS). I haven't used it myself, but I would assume 
you have to put a line

    device=%SYSTEMROOT%\SYSTEM32\ansi.sys

into your config.sys. Alas this is a bummer if you want to transfer the 
script to other machines.

Alternatively you can use Win32::Console from the libwin32 package 
available on CPAN (you'll already have that if you use ActivePerl).
This works out of the box.

Thomas

-- 
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</  #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..


------------------------------

Date: Tue, 18 May 2004 03:08:52 GMT
From: Derf <wunkalunka@elvis.com>
Subject: installing modules on shared server continued
Message-Id: <Xns94ECE2AC3DBCFwunkalunkaelviscom@24.93.43.121>

I need to install two modules (LWP and Mime::Lite) in my area on a shared 
server where I do not have root access. The instructions in the CPAN FAQ 
say:

o conf makepl_arg "LIB=~/myperl/lib \
                    INSTALLMAN1DIR=~/myperl/man/man1 \
                    INSTALLMAN3DIR=~/myperl/man/man3"
install Mime::Lite

I had thought this was a command to be used from the shell command line, 
but when I type it in and hit enter I get:

o: command not found

Is 'o' a command, or am I just completely on the wrong track here?

Again, thanks for any help.

Derf

The full text of CPAN FAQ item I am quoting is:

Q: I am not root, how can I install a module in a personal directory? 
You will most probably like something like this:

  o conf makepl_arg "LIB=~/myperl/lib \
                    INSTALLMAN1DIR=~/myperl/man/man1 \
                    INSTALLMAN3DIR=~/myperl/man/man3"
  install Sybase::Sybperl
You can make this setting permanent like all o conf settings with o conf 
commit.

You will have to add ~/myperl/man to the MANPATH environment variable and 
also tell your perl programs to look into ~/myperl/lib, e.g. by including

  use lib "$ENV{HOME}/myperl/lib";
or setting the PERL5LIB environment variable.

Another thing you should bear in mind is that the UNINST parameter should 
never be set if you are not root.


------------------------------

Date: Tue, 18 May 2004 03:27:04 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: installing modules on shared server continued
Message-Id: <c8bvq8$gfg$1@wisteria.csv.warwick.ac.uk>


Quoth Derf <wunkalunka@elvis.com>:
> I need to install two modules (LWP and Mime::Lite) in my area on a shared 
> server where I do not have root access. The instructions in the CPAN FAQ 
> say:
> 
> o conf makepl_arg "LIB=~/myperl/lib \
>                     INSTALLMAN1DIR=~/myperl/man/man1 \
>                     INSTALLMAN3DIR=~/myperl/man/man3"
> install Mime::Lite
> 
> I had thought this was a command to be used from the shell command line, 
> but when I type it in and hit enter I get:
> 
> o: command not found
> 
> Is 'o' a command, or am I just completely on the wrong track here?

These should be typed into the CPAN shell, which you can get with

perl -MCPAN -eshell

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


------------------------------

Date: Tue, 18 May 2004 05:22:32 GMT
From: Derf <wunkalunka@elvis.com>
Subject: Re: installing modules on shared server continued
Message-Id: <Xns94ED53285DBAwunkalunkaelviscom@24.93.44.119>

Ben Morrow <usenet@morrow.me.uk> wrote in
news:c8bvq8$gfg$1@wisteria.csv.warwick.ac.uk: 
> 
> These should be typed into the CPAN shell, which you can get with
> 
> perl -MCPAN -eshell

Thank you for that! But that command (perl -MCPAN -eshell) says it wants me 
to be root (mkdir /root/.cpan: Permission denied....)

How do I make the CPAN shell want to use my own little user space on this 
shared server (do I edit my .profile maybe)?

Thanks again for any help!

Derf


------------------------------

Date: Tue, 18 May 2004 10:26:29 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: installing modules on shared server continued
Message-Id: <2gtvlfF6kmaaU1@uni-berlin.de>

Derf wrote:
> I need to install two modules (LWP and Mime::Lite) in my area on a
> shared server where I do not have root access.

I can understand about MIME::Lite (not Mime::Lite; case matters),
since there are quite a few modules for sending emails. However,
installing LWP in the space for a user account makes little sense to
me. LWP is included in a big package called libwww-perl, and even if
it's not part of the standard Perl distribution, decent providers of
web hosting services have it installed at the server level.

I do recommend that you ask the server administrator to install
libwww-perl.

If you have trouble applying the installation instructions, you may
want to install MIME::Lite manually:

- Create the library cgi-bin/lib/MIME
- Get Lite.pm from the distribution and upload it to cgi-bin/lib/MIME
- In the program that shall use MIME::Lite, include

     use lib 'lib';

   at the top (assuming that the program is located in the /cgi-bin
   directory).

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Tue, 18 May 2004 08:57:15 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: installing modules on shared server continued
Message-Id: <c8cj5a$m4v$1@wisteria.csv.warwick.ac.uk>

Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
> - Create the library cgi-bin/lib/MIME
> - Get Lite.pm from the distribution and upload it to cgi-bin/lib/MIME
> - In the program that shall use MIME::Lite, include
> 
>      use lib 'lib';
> 
>    at the top (assuming that the program is located in the /cgi-bin
>    directory).

Gaah! No, don't do that. 1. you don't want anything unnecessary
accessible from the web and 2. you can't make assumptions about the cwd
when running CGI.

If your document root directory is /path/to/htdocs then create the
directory /path/to/perl5lib/MIME and put Lite.pm in *there*. Then put

use lib '/path/to/perl5lib';

i.e. with a full path at the top of your script.

Ben

-- 
                Outside of a dog, a book is a man's best friend.
                Inside of a dog, it's too dark to read.
ben@morrow.me.uk                                                  Groucho Marx


------------------------------

Date: Tue, 18 May 2004 11:36:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: installing modules on shared server continued
Message-Id: <2gu3o0F6m8nhU1@uni-berlin.de>

Ben Morrow wrote:
> Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
> 
>> - Create the library cgi-bin/lib/MIME
>> - Get Lite.pm from the distribution and upload it to
>>   cgi-bin/lib/MIME
>> - In the program that shall use MIME::Lite, include
>> 
>>     use lib 'lib';
>> 
>>   at the top (assuming that the program is located in the 
>>   /cgi-bin directory).
> 
> Gaah! No, don't do that.

Maybe I shouldn't argue, but...

> 1. you don't want anything unnecessary accessible from the web and

Assuming that the cgi-bin is scriptaliased, how would the module
become accessible from the web?

Btw, why would it matter if a CPAN module was accessible from the web?

> 2. you can't make assumptions about the cwd when running CGI.

I have just that ( use lib 'lib'; ) as the default in a script that
I'm distributing with script specific modules, and I can't recall a
single occurrence when it has not been sufficient. (It's another thing
when you run the script under mod_perl.)

Maybe you *can* make assumptions, after all? ;-)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Tue, 18 May 2004 05:37:38 GMT
From: Taylor Carpenter <first_dot_news_dot_20_dot_taylorcc@spameater_.org>
Subject: LWP with Crypt::SSLeay or Net::SSLeay with OpenSSL v0.97c hanging ( 500 read timeout ) 
Message-Id: <Cihqc.106999$NR5.94682@fe1.texas.rr.com>

Hello, 

 

I do not know if this should go to OpenSSL list.  It 

sounds like a OpenSSL bug, but maybe someone can verify. 

 

I was getting 500 read timeouts trying to download a 2MB file at around 

1.5MB (downloading in chunks) with ActiveState Perl and Crypt::SSLeay 

v0.51 compiled against OpenSSL v0.9.7c. 

 

I then tried the same script on a Linux box and it worked fine.  I then 

noticed I was using IO::Socket::SSL and Net::SSLeay rather than 

Crypt::SSLeay on the Linux machine, so I uninstalled Crypt::SSLeay on 

the windows machine and installed the ppm module Net::SSLeay v1.25.  It 

still timed out. 

 

So I installed Crypt::SSLeay on the Linux machine and it did not work. 

After all this I noticed that I had both OpenSSL 0.9.6g and 0.9.7c.  The 

Net::SSLeay was compiled against the 0.9.6g.  I installed a version 

compiled against 0.9.7c and it failed on the download also. 

 

Also downloads were working from the site just a couple of weeks ago, 

and my Crypt::SSLeay install and OpenSSL were not updated or modified. 

I suppose something could have changed with the server that is causing a 

problem to show up in OpenSSL, but I don't know. 

 

Any ideas? 

 

Taylor Carpenter

email: first DOT news DOT 20 DOT taylorcc AT spameater DOT org


------------------------------

Date: Mon, 17 May 2004 23:10:59 -0400
From: Bob <bob.lockie.NOSPAM@mail.com>
Subject: Re: Net::DNS
Message-Id: <19fqc.14055$qJ5.402466@news20.bellglobal.com>

On 05/17/04 20:15 Ben Morrow spoke:
> Quoth Bob <bob.lockie.NOSPAM@mail.com>:
> 
>>How do I specify the port for DNS queries in the Net::DNS module?
> 
> 
> Try perldoc Net::DNS::Resolver:
> 
> | port
> |    Gets or sets the port to which we send queries.

Thanks.


-- 
-------------------------------------------------------
Remove .NOSPAM from my email address to reply directly.


------------------------------

Date: 17 May 2004 18:59:01 -0700
From: clearguy02@yahoo.com (John Smith)
Subject: Parsing a text file.....
Message-Id: <500f84f3.0405171759.57851db8@posting.google.com>

Hi expert,

I have the below scenario.

I have a text file called test.txt with quite a few lines. Then I need
to replace only two words("cleardiff" and "xmldiffmrg") with a common
word, "cleardiffmrg" in a few lines that start with "_xml". I need to
save the same file, test.txt after the replacement is done:

Below is the code:
------------------
open (FILE1, "C:\\test.txt") || die "Can not open the file: $!\n";

@array = <FILE1>;
close FILE1;

open (FILE2, ">C:\\test.txt") || die "Can not write to the merge file:
$!\n";

foreach (@array)
  {
    if (($_ =~ /^_xml\s+merge/) or ($_ =~ /^_xml\s+xmerge/))
      {
        s/cleardiff/cleardiffmrg/g;
        s/xmldiffmrg/cleardiffmrg/g;
        
        print FILE2;
      } 
        
  }
------------------

I get only those two lines, but not the whole file with modified word,
cleardiffmrg.

What is wrong with my code?

Thanks
John

########## test.txt has the following lines########
####start of file###
_rose			annotate			..\..\bin\tfdmgr.exe
_html2			xmerge				..\..\bin\htmlmgr.exe
_html2			annotate			..\..\bin\bdtm.exe
_html2			get_cont_info			..\..\bin\bdtm.exe
_xml2			construct_version		..\..\bin\bdtm.exe
_xml2			create_branch			..\..\bin\bdtm.exe
_xml2			compare				..\..\bin\cleardiff.exe
_xml2			xcompare			..\..\bin\xmldiffmrg.exe
_xml2			merge				..\..\bin\cleardiff.exe
_xml2			xmerge				..\..\bin\xmldiffmrg.exe
_xml2			annotate			..\..\bin\bdtm.exe
_xml2			get_cont_info			..\..\bin\bdtm.exe
_rose2			construct_version		..\..\bin\bdtm.exe
_rose2			create_branch			..\..\bin\bdtm.exe
### end of file ####


------------------------------

Date: Tue, 18 May 2004 02:25:31 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Parsing a text file.....
Message-Id: <c8bs6r$flt$1@wisteria.csv.warwick.ac.uk>


Quoth clearguy02@yahoo.com (John Smith):
> I have a text file called test.txt with quite a few lines. Then I need
> to replace only two words("cleardiff" and "xmldiffmrg") with a common
> word, "cleardiffmrg" in a few lines that start with "_xml". I need to
> save the same file, test.txt after the replacement is done:
> 
> Below is the code:
> ------------------

You have missing here:

use warnings;
use strict;

These catch many common errors.

> open (FILE1, "C:\\test.txt") || die "Can not open the file: $!\n";

It is better to use lexical filehandles than barewords.
It is better to use real rather than backslashes, even on Win32.
It is better to make use of the low-precedence logical operators.
It is better to use meaningful variable names.
It is better to specify the mode to open the file in.
It is better to put the filename in the error message.
It is better not to end die() messages with "\n", as this suppresses
useful information.

open my $IN, '<', 'C:/test.txt' or die "cannot open test.txt: $!";

> @array = <FILE1>;

You need to declare this variable under strictures.

my @array = <$IN>;

But in fact, since you are processing the file line-by-line, you don't
need to read it all in at all.

> close FILE1;

One of the advantages of lexical FHs is that they close themselves at
the end of their scope (of course, if the FH is attached to something
other than a file you may still wish to close it yourself to catch
errors).

> open (FILE2, ">C:\\test.txt") || die "Can not write to the merge file:
> $!\n";

Hang on; I see, you read it all in as you're replacing it. It's safer to
open a new file and rename it over the top when you're done: that way,
if the script dies halfway through it doesn't trash your data.

> foreach (@array)

while (<$IN>) {

>   {
>     if (($_ =~ /^_xml\s+merge/) or ($_ =~ /^_xml\s+xmerge/))

$_ is the default target for pattern matches; there is no need for =~
here.
The textual logic operators are deliberately low-precedence, so you can
omit the parentheses.
Those two can be trivially simplified into one regex.

    if (/^_xml\s+x?merge/) {

or with some whitespace for clarity

    if (/^ _xml \s+ x?merge/x) {

>       {
>         s/cleardiff/cleardiffmrg/g;
>         s/xmldiffmrg/cleardiffmrg/g;
>         
>         print FILE2;

Here is your bug. The print is inside the if, so you only end up
printing lines that matched.

>       } 
>         
>   }

I would do the whole thing as a one-liner:

perl -pi~ -e'/^_xml\s+x?merge/ and 
    do { s/(cleardiff)/$1mrg/g; s/xml(diffmrg)/clear$1/g; }'

but that is perhaps an acquired taste :).

> _xml2			merge				..\..\bin\cleardiff.exe
> _xml2			xmerge				..\..\bin\xmldiffmrg.exe

I note that the file has /^_xml2\s+/ rather than /^_xml\s+/...?

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else ** ben@morrow.me.uk


------------------------------

Date: Tue, 18 May 2004 06:20:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Parsing a text file.....
Message-Id: <40A9AB35.9FAE97D8@acm.org>

John Smith wrote:
> 
> I have a text file called test.txt with quite a few lines. Then I need
> to replace only two words("cleardiff" and "xmldiffmrg") with a common
> word, "cleardiffmrg" in a few lines that start with "_xml". I need to
> save the same file, test.txt after the replacement is done:
> 
> Below is the code:
> ------------------
> open (FILE1, "C:\\test.txt") || die "Can not open the file: $!\n";
> 
> @array = <FILE1>;
> close FILE1;
> 
> open (FILE2, ">C:\\test.txt") || die "Can not write to the merge file:
> $!\n";
> 
> foreach (@array)
>   {
>     if (($_ =~ /^_xml\s+merge/) or ($_ =~ /^_xml\s+xmerge/))
>       {
>         s/cleardiff/cleardiffmrg/g;
>         s/xmldiffmrg/cleardiffmrg/g;
> 
>         print FILE2;
>       }
> 
>   }
> ------------------
> 
> I get only those two lines, but not the whole file with modified word,
> cleardiffmrg.

This is one way to do it:

( $^I, @ARGV ) = ( '.bak', 'C:/test.txt' );
while ( <> ) {
    /^_xml\s+x?merge/ and
        s/\b(?:xmldiffmrg|cleardiff)\b/cleardiffmrg/g;
    print;
    }



John
-- 
use Perl;
program
fulfillment


------------------------------

Date: Tue, 18 May 2004 08:39:03 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Parsing a text file.....
Message-Id: <c8catl$1dm$1@nntp.fujitsu-siemens.com>

John Smith wrote:
> Hi expert,
>=20
> I have the below scenario.
>=20
> I have a text file called test.txt with quite a few lines. Then I need
> to replace only two words("cleardiff" and "xmldiffmrg") with a common
> word, "cleardiffmrg" in a few lines that start with "_xml". I need to
> save the same file, test.txt after the replacement is done:
>=20
> Below is the code:
> ------------------
> open (FILE1, "C:\\test.txt") || die "Can not open the file: $!\n";
>=20
> @array =3D <FILE1>;
> close FILE1;
>=20
> open (FILE2, ">C:\\test.txt") || die "Can not write to the merge file:
> $!\n";
>=20
> foreach (@array)
>   {
>     if (($_ =3D~ /^_xml\s+merge/) or ($_ =3D~ /^_xml\s+xmerge/))
>       {
>         s/cleardiff/cleardiffmrg/g;
>         s/xmldiffmrg/cleardiffmrg/g;
>        =20
>         print FILE2;
>       }=20
>        =20
>   }

A hint to get you on track:
Under what condition do you change a line?
Under what condition do you print to the new file?
Under what condition do you want to print to the new file?

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



------------------------------

Date: Tue, 18 May 2004 04:37:39 GMT
From: rossz <rosszNOSPAM@vamos-wentworth.org>
Subject: perlmagick and image size
Message-Id: <nqgqc.11804$Fo4.153620@typhoon.sonic.net>

I've been trying to use the perlmagick module to do the following, but 
haven't been having much luck.

I need to adjust an image to a minimum size, but without distoring it, 
so I basically want to add space evenly around the existing image. 
Using Resize is out since that will distort the image, so I gave 
"Composite" a shot, though there doesn't seem to much in the way of docs 
for this.  My attempt results in this error message:

"Exception 410: reference is not my type `Image::Magick' at ./img.pl 
line 23."

That's the "Composite" line.

Any suggestions on how to get this done would be appreciated.  I have a 
few thousand images I need to process so I would rather avoid doing this 
manually.  Useless and broken code follows (simplified).  Both 
ImageMagick and PerlMagick are the latest (afaik).

#!/usr/bin/perl


use Image::Magick;

$img = new Image::Magick;

$img->Read('test1.jpg');
($width,$height) = $img->Get('width','height');

$w = 100;  # minimum sizes
$h = 100;

$w = $width if $w < $width;  # if the axis is larger than the minimum, 
leave it as is
$h = $height if $h < $height;

$x = int(($w-$width)/2);  # position adjustment to keep it centered
$y = int(($h-$height)/2);

$geometry = $w."x".$h;  # e.g "100x100"
$new = new Image::Magick(size=>$geometry);
$new->ReadImage('xc:white');
$z = $new->Composite(image=>$p, compose=>atop, gravity=>"SouthEast", 
x=>$x, y=>$y);
print "$z\n" if "$z";
$new->Write('x.jpg'); # never gets this far

--
Rossz


------------------------------

Date: Tue, 18 May 2004 06:50:30 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: perlmagick and image size
Message-Id: <c8cbko$fsa$1@news.simnet.is>

"rossz" <rosszNOSPAM@vamos-wentworth.org> wrote in message
news:nqgqc.11804$Fo4.153620@typhoon.sonic.net...

[ problem resizing image to fixed size without distortion]

>
> "Exception 410: reference is not my type `Image::Magick' at ./img.pl
> line 23."

[ snip code ]
> $z = $new->Composite(image=>$p, compose=>atop, gravity=>"SouthEast",
> x=>$x, y=>$y);

what is this image=>$p ?
should there not be $img there ?

also, you still need to resize the image.

you should:
a) determine needed scaling factor
   $sf=$min/max($width,$height);
b) resize image to $width*$sf,$height*$sf
c) create blank image size $min,$min
d) calculate offsets, as you did
e) paint resized image into new image at
   appropriate offsets. (can't be bothered
   to look at the docs to see if Composite()
   is the correct method, but it sounds familiar)

gnari






------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6576
***************************************


home help back first fref pref prev next nref lref last post