[24334] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6523 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 5 14:05:51 2004

Date: Wed, 5 May 2004 11:05:14 -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           Wed, 5 May 2004     Volume: 10 Number: 6523

Today's topics:
    Re: Background jobs in Perl <mark.clements@kcl.ac.uk>
    Re: Background jobs in Perl <dwall@fastmail.fm>
    Re: Background jobs in Perl <bxb7668@somewhere.nocom>
    Re: Chat Server and Time Delay <dwall@fastmail.fm>
    Re: Chat Server and Time Delay <mark.clements@kcl.ac.uk>
    Re: Creating Dynamic variables from CGI.pm Param() <dwall@fastmail.fm>
    Re: Creating Dynamic variables from CGI.pm Param() <jds@nospantrumpetweb.co.uk>
    Re: First edition of _Programming perl_, how useful is  bishop@speakeasy.net
    Re: forking an independent process ctcgag@hotmail.com
    Re: forking an independent process <bxb7668@somewhere.nocom>
    Re: free source authentication script <tassilo.parseval@rwth-aachen.de>
    Re: Help Needed Building Array Of Hashes From CSV <tore@aursand.no>
        HTML::LinkExtor or me ? (Saya)
    Re: Komodo as a editor? <dwall@fastmail.fm>
    Re: multimap equivalent in perl <ittyspam@yahoo.com>
    Re: Newbie question, logical operators <zturner_NOSPAM_0826@hotmail.com>
    Re: Newbie question, logical operators <xxala_qumsiehxx@xxyahooxx.com>
        Out of memory problem (Shikhar)
    Re: Please Recommend A Good Perl Book. (Greg Bacon)
        Removing windows CR-LF from middle of text (v796)
    Re: Removing windows CR-LF from middle of text <mark.clements@kcl.ac.uk>
    Re: Where's documentation for import ??? ctcgag@hotmail.com
    Re: Win32::API and SetEnvironmentVariable (Shawn Campbell)
    Re: Win32::API and SetEnvironmentVariable <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 05 May 2004 16:00:17 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Background jobs in Perl
Message-Id: <40990176$1@news.kcl.ac.uk>

Mark J Fenbers wrote:

> In my Perl script, I want to launch a command and not wait for it to
> return before moving on.
<snip>

> In Perl, can I just do this:
> 
>     `/home/fenbers/myscript.bash &`;
what happens when you try it?

Anyway: you probably want to fork and then use system or whatever in the child. perldoc 
perlfork. You may also want to look at perldoc perlipc, specifically the double-fork trick.

Mark


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

Date: Wed, 05 May 2004 15:25:15 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Background jobs in Perl
Message-Id: <Xns94E0742DE41F2dkwwashere@216.168.3.30>

Mark J Fenbers <Mark.Fenbers@noaa.gov> wrote:

> In my Perl script, I want to launch a command and not wait for it to
> return before moving on.

perldoc -f exec

The "exec" function executes a system command *and never
returns* -- use "system" instead of "exec" if you want it to
return. It fails and returns false only if the command does not
exist *and* it is executed directly instead of via your system's
command shell (see below).

 ...


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

Date: Wed, 5 May 2004 15:11:30 GMT
From: "bxb7668" <bxb7668@somewhere.nocom>
Subject: Re: Background jobs in Perl
Message-Id: <Hx8y74.5DC@news.boeing.com>

I don't know which is better, but another way would be to use the
system command, i.e.
   system '/home/fenbers/myscript.bash &';

"Mark J Fenbers" <Mark.Fenbers@noaa.gov> wrote in message
news:4098F6C2.FA9D6C13@noaa.gov...
> In my Perl script, I want to launch a command and not wait for it to
> return before moving on.
>
> In a Bash script, I can do it this way:
>
>     /home/fenbers/myscript.bash &
>
> In Perl, can I just do this:
>
>     `/home/fenbers/myscript.bash &`;
>
> Or is there a better way of doing this?
>
> Mark
>




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

Date: Wed, 05 May 2004 13:55:00 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Chat Server and Time Delay
Message-Id: <Xns94E064E0F8947dkwwashere@216.168.3.30>

Ben Morrow <usenet@morrow.me.uk> wrote:

> Quoth Mark Clements <mark.clements@kcl.ac.uk>:
>> Brian wrote:
>> 
>> > First one sits on a server and runs without being called
>> > from a browser. It's job is to check the time, and if
>> > the time = X then do Y. basically I want a script that
>> > is going to clear a MySQL Db at 4 am every day
>>
>> use cron, or the equivalent on windows (Scheduled Tasks?). This
>> will automatically execute a specified command according to
>> whatever schedule you set.
> 
> We seem to be getting this quite a lot atm. Would it be worth
> writing a faq answer?

It's not really a Perl problem, though, is it? Even if someone were to 
write a "canned" response for it, I very much doubt it would be added 
to the "official" Perl FAQ list. And what more can you say besides "use 
cron or the equivalent on your OS"?



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

Date: Wed, 05 May 2004 15:07:58 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Chat Server and Time Delay
Message-Id: <4098f533$1@news.kcl.ac.uk>

David K. Wall wrote:

>>>use cron, or the equivalent on windows (Scheduled Tasks?). This
>>>will automatically execute a specified command according to
>>>whatever schedule you set.
>>We seem to be getting this quite a lot atm. Would it be worth
>>writing a faq answer?
> It's not really a Perl problem, though, is it? Even if someone were to 
> write a "canned" response for it, I very much doubt it would be added 
> to the "official" Perl FAQ list. And what more can you say besides "use 
> cron or the equivalent on your OS"?
As you say, it isn't really a Perl problem, but it is a faq for the list and therefore probably 
worthwhile. It could come under a section called somethings like "these aren't Perl questions 
but here's how you solve them." It may give posters a hint as to what constitutes a non-Perl 
question. That being said, you can lead a horse to water, but you can't make it drink.

Mark


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

Date: Wed, 05 May 2004 15:21:04 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Creating Dynamic variables from CGI.pm Param()
Message-Id: <Xns94E0737822774dkwwashere@216.168.3.30>

Julia deSilva <jds@nospantrumpetweb.co.uk> wrote:

> I use something like this to process form elements
> 
> my $field;
> foreach $field ($q->param()) {
>         ${$field}  = $q->param($field);
>         .....
>         .....
>}
> 
> to retreive data from a dynamically created webpage where I do not
> know either the number or names of the form elements.
> 
> The above can't work under strict.

Exactly. Strictures exist to keep you from doing dangerous things like 
that. For a discussion of why what you're doing is a bad idea, see 
http://perl.plover.com/varvarname.html



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

Date: Wed, 5 May 2004 17:34:18 +0100
From: "Julia deSilva" <jds@nospantrumpetweb.co.uk>
Subject: Re: Creating Dynamic variables from CGI.pm Param()
Message-Id: <gI8mc.69$DR2.13@nurse.blueyonder.net>

> Exactly. Strictures exist to keep you from doing dangerous things like
> that. For a discussion of why what you're doing is a bad idea, see
> http://perl.plover.com/varvarname.html

Thanks for that. I'm fixing it now. Out of date Perl book was to blame




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

Date: Wed, 05 May 2004 10:27:17 -0500
From: bishop@speakeasy.net
Subject: Re: First edition of _Programming perl_, how useful is it?
Message-Id: <2PadnXNb4YhImgTd38DK-w@speakeasy.net>

Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "Alex" == Alex Withers <awithers@barney.gonzaga.edu> writes:
> Alex> I have a first edition of _Programming perl_ and I am curious as to
> Alex> how much of it is obsolete and/or irrelevant.
> 
> I had to chuckle, because I read that as "irreverent". :)

I wondered what that was you were chuckling at, at the computer next to
mine that morning.  But you certainly are irreverent.

Speaking of older editions of Camel, I still only have a second edition.
Is it worth getting the third edition even if your name is not on it any
more?

-E



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

Date: 05 May 2004 15:38:14 GMT
From: ctcgag@hotmail.com
Subject: Re: forking an independent process
Message-Id: <20040505113814.085$UB@newsreader.com>

"bxb7668" <bxb7668@somewhere.nocom> wrote:
> From my perl script I need to be able to launch (fork?) an editor
> (notepad on Windows and nedit on UNIX). (Easy so far.) I need the
> script to processing and the editor to keep editing totally
> independent of each other. The script can end and the editor will stay
> open. The editor can be closed and the script will keep running.
> Reading up on fork gave me this:
>
> #!/usr/bin/perl
> FORK: {
>         if ($pid = fork) {
>                 $I = 1;
>                 while ( 1 ) {
>                         print "hi $I\n";
>                         sleep 1;
>                         $I++;
>                }
>         }elsif (defined $pid) {
>                 exec "nedit junk.txt";
>         }elsif ( $! =~ /no more process/) {
>                 sleep 5;
>                 redo FORK;
>         }else {
>                 die "Can't fork";
>         }
> }
>
> When I close the child nedit process, the parent keeps going. But when
> I close the parent with a Ctrl+C, it also kills the nedit window.  Is
> what I'm trying for possible?  If so, how?

Don't kill the parent with ctrl+C.  The problem probably lies in the shell
from which you execute the perl script.  When you hit ctrl+C, the shell
kills the running perl script and everything else in the its process group,
which includes the nedit children.  If the parent ends naturally, or is
killed by signal sent specifically to its pid, then nedit stays open.

You may also be able to circumvent the problem by using
system "nedit blah.txt&"
instead of a fork.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Wed, 5 May 2004 15:18:44 GMT
From: "bxb7668" <bxb7668@somewhere.nocom>
Subject: Re: forking an independent process
Message-Id: <Hx8yJ7.5ow@news.boeing.com>

Thank you Ala. That is exactly what I needed.

"Ala Qumsieh" <xxala_qumsiehxx@xxyahooxx.com> wrote in message
news:wEUlc.44980$xc.21470@newssvr29.news.prodigy.com...
> "bxb7668" <bxb7668@somewhere.nocom> wrote in message
> news:Hx7Lp4.Enp@news.boeing.com...
> > From my perl script I need to be able to launch (fork?) an editor
> > (notepad on Windows and nedit on UNIX). (Easy so far.) I need the
> > script to processing and the editor to keep editing totally
> > independent of each other. The script can end and the editor will
stay
> > open. The editor can be closed and the script will keep running.
>
> I wouldn't even go with fork() here:
>
>     # untested code:
>     if ($^O eq 'MSWin32') {
>       system 'start notepad.exe';
>     } else { # unix
>       system 'nedit &';
>     }
>
> Unless I misunderstood you, that should be enough.
>
> --Ala
>
>




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

Date: Wed, 5 May 2004 17:54:05 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: free source authentication script
Message-Id: <c7b2n0$1opp1$1@ID-231055.news.uni-berlin.de>

Also sprach Tore Aursand:

> On Tue, 04 May 2004 22:22:45 -0800, Robin wrote:
>> www.infusedlight.net/robin/temp/auth.txt
> 
> A short summary:
> 
>   * You're _still_ not indenting your code properly.

Well, it was indented this time. The curlies were just arranged in a
rather odd and - for me anyways - unpleasant way.

>   * You're _still_ mixing HTML and Perl code.

I'd rather gnaw my arm off than recommending the use of a templating
system to anyone. I tried quite a few and hated each one of them.

Perl already is the best templating system around with all its
capabilities of interpolating variables and code in strings. Templating
systems tend to come with their own syntax. This is a waste of time when
considering that one already knows Perl.

A necessary corollary from that is that HTML and Perl code will be
mixed. It's the same with templating systems. There you'll have HTML
mixed with the templating system's code. I fail to see the advantage of
that.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 05 May 2004 15:41:26 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Help Needed Building Array Of Hashes From CSV
Message-Id: <pan.2004.05.05.13.35.52.457744@aursand.no>

On Wed, 05 May 2004 12:46:53 +0000, Tim Sheets wrote:
>> Instead of using your own routine to parse CSV, you should consider one
>> of the CSV modules on CPAN - <http://www.cpan.org/> - or
>> Text::ParseWords (which comes with Perl).

> I thought of that, but decided to try to make it happen myself.

That is good if you intend to learn, but never try to reinvent the wheel
when you're done learning.

> More portable if you don't have to install an additional module [...]

Text::ParseWords comes with the standard Perl distribution, and what's the
problem with installing your own modules?  You don't have to be superuser
to be able to do that.


-- 
Tore Aursand <tore@aursand.no>
"There are three kinds of lies: lies, damn lies, and statistics."
 (Benjamin Disraeli)


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

Date: 5 May 2004 07:37:23 -0700
From: vahu@novonordisk.com (Saya)
Subject: HTML::LinkExtor or me ?
Message-Id: <9e9517bf.0405050637.30399fb4@posting.google.com>

Hi, 

This is the code:

sub Escape{
	$item = shift;

	use HTML::LinkExtor;
	
	$p = HTML::LinkExtor->new(\&replaceURL, "");
	$p->parse($item);
	
	return $item;
}


sub replaceURL {
     
my(@links) = @_;


     my $makeSubstitution = false;
     my $newLink;

	foreach  my $link (@links) {
		#$link =~ s/\/$//i;
		$makeSubstitution = compareValues($link);
		
		if ($makeSubstitution eq true) {
			 if($link =~ /http|www/) {
				if ($link !~ /http/) {
					$newLink = "http://" . $link;
				}
				else {
					$newLink = $link;
				}
				$item =~ s/href=\"$link/href=\"\/redirect.asp?forwardURL=$newLink/i;
			 }
		 }
		 else {
			if($link =~ /http|www/) {
				if ($link !~ /http/) {					
					$item=~ s/href=\"$link/href=\"http:\/\/$link/i;
				}
			}	
		 }
	 }	 	 	 
}

sub compareValues {
	my $link = shift;

	my @safeLinkArr;
	@safeLinkArr = getSafeSites();
	my $sizeOfArray = @safeLinkArr;
	my $result = true;

	if($sizeOfArray eq 0) {
		return $result;
	}

	foreach my $safeLink (@safeLinkArr) {

		if ( (0 <= (index($link, $safeLink))) or (0 <= (index($safeLink,
$link))) ) {
			$result = false;
			last;
		}
		else {
			$result = true;
		}
	}

	return $result;
}



sub getSafeSites {
	use XML::DOM;	

	my $count;	
	my $WAPath;
	my @linkArr;


	foreach $arg (@ARGV)
	{			
		if ($ARGV[$count] eq '-iw_include-location')
		{
			$WAPath = $ARGV[$count + 1];
		}
		$count++;
	}

	my $nonRedirectList = $WAPath . "/include/nonRedirectList.xml";

	# --- Parsing the XML file ---
	my $parser = XML::DOM::Parser->new();
	my $doc = $parser->parsefile($nonRedirectList);
	
	# --- get all  tags ---
	my $links = $doc->getElementsByTagName('Link');
	my $link;

	for my $i (0..$links->getLength()-1) {
		$link = $links->item($i);

		if ($link->getFirstChild->getNodeValue) {
			@linkArr[$i] = $link->getFirstChild->getNodeValue;
		}
		$i++;
	}

	$doc->dispose;

	return @linkArr;
}

Escape($item);

$item = is real scenario is text + <a> + text <a> etc. 

For some reason that I do not understand some links are not parsed
correctly. Does anyone have a reason for why this might be happening ?

I have looked at this problem for 2 days now, and can not find the
problem, so any help will be greatly appreciated :-)

/Saya


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

Date: Wed, 05 May 2004 14:00:23 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Komodo as a editor?
Message-Id: <Xns94E065CABF83Cdkwwashere@216.168.3.30>

Robert <catcher@linuxmail.org> wrote:

> I am evaluating Komodo as an editor for work. I am doing a lot of
> Perl work as a sysadmin and am starting to get into Perl/Tk as
> well. We use PVCS for version control and I see Komodo integrates
> with that. 
> 
> All that to say "Do you use it and what do you think about it?".

I think comp.editors is a better place to ask this question.


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

Date: Wed, 5 May 2004 10:34:51 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: multimap equivalent in perl
Message-Id: <20040505103304.P25082@dishwasher.cs.rpi.edu>

On Wed, 4 May 2004, Kapil Khosla wrote:

> Hi,
> I am new to perl and am trying to count the number of instances of
> unique strings in a file. The strings are like
>
> s1\aaa s1\bbb s1\ccc s1\ddd s1\aaa s1\aaa s1\aaa s1\aaa s1\eee
>
> Currently, I have no good way to count unique strings in the file.
> This could be easily done using the multimap functionality in C++.
>
> I read about associative arrays but they seem to be more like unique
> key / value combination. Would you know how best could I count the
> number of unique strings in a file. I am not looking for code, just a
> pointer in the right directin.
>
> Thanks for your help,
> Kapil

If you want a pointer to the right information, the FAQ is generally a
good place to start.  In this case, the appropriate FAQ can be found by
typing
perldoc -q word-frequency
into your shell

And yes, associative arrays are indeed unique key/value combinations.  In
your case, the keys would be the unique strings, and the values are the
number of times those strings have appeared.

Hope this helps,
Paul Lalli


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

Date: Wed, 05 May 2004 16:58:57 GMT
From: "Zachary Turner" <zturner_NOSPAM_0826@hotmail.com>
Subject: Re: Newbie question, logical operators
Message-Id: <l39mc.66619$NR5.4603@fe1.texas.rr.com>

>
> Admittedly, and as pointed out by others, my examples 1 & 3 have nothing
> to do with && and || returning one of their operands' values. As for an
> example using &&, the only thing I can think of is this. Instead of:
>
> $x = $flag ? $y : $z;
>
> you can do:
>
> $x = $flag && $y || $z;
>
> but in this case I would argue against it since it's more cryptic, and
> even longer to type.

Hmm...  Is one faster than the other perhaps?  I imagine the first one is
faster, because no matter what it only makes one comparison.  Also this
makes me think of another question.  I'm assuming that Perl groups these as

($flag && $y) || $z

Is my guess correct?




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

Date: Wed, 05 May 2004 17:16:01 GMT
From: "Ala Qumsieh" <xxala_qumsiehxx@xxyahooxx.com>
Subject: Re: Newbie question, logical operators
Message-Id: <lj9mc.45271$y%6.21484@newssvr29.news.prodigy.com>

"Zachary Turner" <zturner_NOSPAM_0826@hotmail.com> wrote in message
news:l39mc.66619$NR5.4603@fe1.texas.rr.com...

> Hmm...  Is one faster than the other perhaps?  I imagine the first one is
> faster, because no matter what it only makes one comparison.  Also this

Your C++ background is showing quite clearly here :)
I doubt if any Perl coder cares whether one is faster than the other in this
case. There are cases, of course, where speed is important, but I'd rather
care about readability (and, hence, maintainability) unless there are
obvious speed advantages.

So, to answer your question, I don't know, but I would imagine you are
right.

> makes me think of another question.  I'm assuming that Perl groups these
as
>
> ($flag && $y) || $z
>
> Is my guess correct?

Yes. && has slightly higher precedence than || (as described in perlop).
Short-circuiting ensures that $z doesn't get evaluated unless ($flag && $y)
evaluates to false.

--Ala




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

Date: 5 May 2004 10:49:30 -0700
From: shikhar_srivastava@tufts-health.com (Shikhar)
Subject: Out of memory problem
Message-Id: <aeb90a85.0405050949.6e18dc04@posting.google.com>

Perl Gurus,

I have a Perl program that reads certain file(s) and stores contents
in hash maps. The files are not huge per se,. One of the file is 100
bytes long * 100,000 records (80 megs).


I have always thought/read that Perl can read whole file and work
efficiently.  I had this program running nicely with a 40 meg file.
Now I am getting "Out of Memory!" problem with 80 meg file.


In Java I can use heap size parameters to set initial and maximum heap
sizes and they work nicely.

How can I deal with situation here.   I checked in Top and memory
utilization for the process was  around 56,264 K which does not seem a
lot.


System : HP-UX 11.0
This is perl, v5.6.1 built for PA-RISC1.1-thread-multi
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 627 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 21:42:53 Jun 20 2001

Memory Info

4 gb physical

From glance : Total VM : 279.5mb   Sys Mem  : 270.6mb   User Mem: 
1.50gb   Phys Mem:  4.00gb


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

Date: Wed, 05 May 2004 16:55:48 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Please Recommend A Good Perl Book.
Message-Id: <109i74k5j85h023@corp.supernews.com>

In article <2e12fbc.0404290201.3e68f45@posting.google.com>,
    Daniel N. Andersen <daniel_n_andersen@yahoo.com> wrote:

: If it wasn't for that site, I wouldn't own all the new editions of
: those books (except 'Learning Perl on Win32 Systems' which I haven't
: read) today. [...]

Economic analysis seems to point the same direction:

    Also, experience suggests that online and offline books
    are different goods that serve different purposes (quick
    reference versus deep reading; quote checking versus
    extended study; etc.). What's more, these different
    purposes are complementary. On and offline books are
    complements (like bacon and eggs) not substitutes (like
    bacon and sausage).

    http://www.mises.org/fullstory.asp?control=1473

FTR, I'm only arguing that ORA and other publishers ought to toss
RIAA's playbook in the trash, not, for example, that people ought
to make unauthorized publications.

But what do I know?  I own Perl books mostly for the sake of owning
them, and I'm no MP3 ripper/burner/trader/whatever.

Actually, I can't wait to own a copy of mjd's upcoming book[*] and
plan to spend lots of time (re)reading the dead tree rendering, but he
secured contract terms that will allow him to publish the complete
text beerfree on the web.  I don't know his motivation behind this
particular move, but the indication is (and I'm sure all our hopes are)
that it will help rather than hurt his royalties.

[*] http://perl.plover.com/book/

Greg
-- 
Some in the industry scream "document more and you'l have less bugs and
better design". They call doing boring things "discipline". We call it
"adding risk".
    -- Phlip in comp.software.extreme-programming


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

Date: 5 May 2004 07:43:14 -0700
From: vicky7909@rediffmail.com (v796)
Subject: Removing windows CR-LF from middle of text
Message-Id: <49f90fb9.0405050643.7497783d@posting.google.com>

Hi,
I have text on multiple lines in text files on Windows. Example: 
" Your voting instructions have been
 received.
Thank you! "

I need a regex to remove CR-LF and convert them to space in the middle
of the text. I tried this regex which works at the end.
$content =~ s/^([\s\S]+\S)\s*$/$1/;

This works to remove all CR-LF of Windows at the end an puts into $1.
I must remove the CR-LF in the middle too. How can this be done?

My script is running on Linux.
Finally, I have to import $content into a single column in Excel file.
Unfortunately, the excel file requirement just came up yesterday, else
I would have used CPAN WriteExcel module. Oh well!

Currently the text in excel writes to multiple lines in Excel file,
when it should only be in 1 cell.

Any comments are appreciated.

Thanks,
vk


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

Date: Wed, 05 May 2004 16:11:10 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Removing windows CR-LF from middle of text
Message-Id: <40990402$1@news.kcl.ac.uk>

v796 wrote:

> Hi,
> I have text on multiple lines in text files on Windows. Example: 

> I need a regex to remove CR-LF and convert them to space in the middle
> of the text. I tried this regex which works at the end.
> $content =~ s/^([\s\S]+\S)\s*$/$1/;
Your re doesn't do this at all: it's merely stripping whitespace from the end of lines that end 
with non-whitespace followed by whitespace. [\s\S]+ (match white-space or non-whitespace, one or 
more times) will pretty much match anything. You could try dropping the end-of line anchor.

eg

$content =~ s/\r\n/ /g;

> This works to remove all CR-LF of Windows at the end an puts into $1.
> I must remove the CR-LF in the middle too. How can this be done?

> Finally, I have to import $content into a single column in Excel file.
> Unfortunately, the excel file requirement just came up yesterday, else
> I would have used CPAN WriteExcel module. Oh well!
how does this prevent you from using it? It isn't going to be quicker to implement it from scratch?

> Currently the text in excel writes to multiple lines in Excel file,
> when it should only be in 1 cell.
what text in excel? what are you trying at the moment?

I suggest you write the output to a csv and get excel to import it, or using DBD::Excel. Failing 
all that you could look at running Win32::OLE under Windows. You need to learn how to use CPAN...

regards,

Mark


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

Date: 05 May 2004 15:58:27 GMT
From: ctcgag@hotmail.com
Subject: Re: Where's documentation for import ???
Message-Id: <20040505115827.165$6U@newsreader.com>

Amanda <aman_DO_da345@al_THE_ter_OBVIOUS_n.org> wrote:
> In <c797pt$9si$1@wisteria.csv.warwick.ac.uk> Ben Morrow
> <usenet@morrow.me.uk> writes:
>
> >Quoth Amanda aman_DO_da345@al_THE_ter_OBVIOUS_n.org:
>
> >> Yes, I have read perlfunc on "use" and "import", and I have read
> >> perlmod, and I have read the manpage for Exporter.  None of these
> >> documents comes even close to explaining what import is supposed
> >> to do; they don't even explain what import's input and output
> >> signatures are.
>
> >I'm not sure... could you explain
>
> I thought I was perfectly clear.

You were wrong.

> I want to understand *exactly*
> what import is supposed to do.  The cute (and/or disingenuous)
> answer to this question is "import can do whatever you want it to
> do"--i.e. a perfectly worthless API in a nutshell.

It seems a bit weird to call import an API.  import does exactly what you
tell it to do.  Exporter's import does what Exporter's documentation
says it does.


> A less cute,
> but almost as worthless, answer would be, "import is supposed to
> do what the canonical example of import, namely Exporter's, does".
> Unfortunately the Exporter man page does not say a word about what
> its import does.

       The Exporter module implements an "import" method which allows a
       module to export functions and variables to its users' namespaces.
       Many mod- ules use Exporter rather than implementing their own
       "import" method because Exporter provides a highly flexible
       interface, with an imple- mentation optimised for the common case.

That seems pretty clear to me.

> I really don't understand why the Perl documentation has chosen to
> be so coy on import; it treats Perl programmers like children who
> shouldn't be trusted with such sensitive information (which makes
> the ubiquitous little sermons on programmer responsibility all
> throughout the documentation all the more annoying).  The fact that
> import is not a built-in is a technicality.  It is every bit as
> important as many built-ins (e.g. "use"), and it deserves to be
> better documented.

It is documented perfectly well.


> And no, source code is no substitute for documentation (otherwise
> many trees should have been saved by never printing the Camel book
> and its ilk).

Also, documentation is no substitute for code.  If you want to know
exactly what it does, read the source.  If you want to know what it is
documented to do, read the documentation.  If you don't understand
the documentation, point out what you don't understand; don't lie to
use about what is or isn't in the documentation.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 5 May 2004 09:29:39 -0700
From: smc0862.usa@mindspring.com (Shawn Campbell)
Subject: Re: Win32::API and SetEnvironmentVariable
Message-Id: <8ce1e050.0405050829.4fbca6df@posting.google.com>

Eric Bohlman <ebohlman@earthlink.net> wrote in message news:<Xns94DFB77DFE349ebohlmanomsdevcom@130.133.1.4>...
> Ben Morrow <usenet@morrow.me.uk> wrote in 
> news:c791n4$5gm$1@wisteria.csv.warwick.ac.uk:
> 
> > 
> > Quoth smc0862.usa@mindspring.com (Shawn Campbell):
> >> I'm having a problem setting environment variables with a large
> >> string.  According to the MSDN documentation, an environment variable
> >> can be up to 32k.  I'm well under this value, but it's not being set.
> >> 
> >> Following is the code I'm using.
> > 
> > <snip Win32::API SetEnvironmentVar>
> > 
> > Why do you not just use %ENV? (Is there something I'm missing?)
> 
> I presume he's doing it for the reasons listed by perldoc -q environment

Actually, it looks like the SetEnvVar sub I created is working fine,
other than truncating the value at 1024.  The problem was in the
GetEnvVar sub I created.  I didn't supply enough buffer size so it
wasn't reading in the value, giving me the impression it was not set.

I have another environment variable issue I am struggling with that I
hope you could give me some insight on.

I'm using ActivePerl to create an automated build process.  Part of
the process is setting the LIB, INCLUDE, PATH, SOURCE variables from
within the Perl script and then using a system call to invoke
MSDEV.EXE using the /USEENV option.  It looks like the process the
Perl script is running in is setting the variables I need, but MSDEV
is not finding them.  If I manually set the same values within the DOS
console and then run my Perl script, MSDEV finds the variables.

I'm working on Windows XP, so I'm not sure if this might be the issue,
but it behaves as if MSDEV is not looking at the process that the Perl
script is running in, but is looking at it's parent for the
environment variables.

Is there any way of setting environment variables within the 'parent'
DOS process from the PErl script?

Thanks for any help provided.

-Shawn Campbell


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

Date: Wed, 5 May 2004 16:50:26 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Win32::API and SetEnvironmentVariable
Message-Id: <c7b60i$mu0$1@wisteria.csv.warwick.ac.uk>


Quoth smc0862.usa@mindspring.com (Shawn Campbell):
> Eric Bohlman <ebohlman@earthlink.net> wrote in message news:<Xns94DFB77DFE349ebohlmanomsdevcom@130.133.1.4>...
> > Ben Morrow <usenet@morrow.me.uk> wrote in 
> > news:c791n4$5gm$1@wisteria.csv.warwick.ac.uk:
> > 
> > > 
> > > Quoth smc0862.usa@mindspring.com (Shawn Campbell):
> > >> I'm having a problem setting environment variables with a large
> > >> string.  According to the MSDN documentation, an environment variable
> > >> can be up to 32k.  I'm well under this value, but it's not being set.
> > >> 
> > >> Following is the code I'm using.
> > > 
> > > <snip Win32::API SetEnvironmentVar>
> > > 
> > > Why do you not just use %ENV? (Is there something I'm missing?)
> > 
> > I presume he's doing it for the reasons listed by perldoc -q environment
> 
> Actually, it looks like the SetEnvVar sub I created is working fine,
> other than truncating the value at 1024.  The problem was in the
> GetEnvVar sub I created.  I didn't supply enough buffer size so it
> wasn't reading in the value, giving me the impression it was not set.

Can you clarify: does SetEnvironmentVar simply set the var for the
current process, or does it change the default environment in the
registry? If it does the former, then there really is no reason not to
simply use %ENV.

> I have another environment variable issue I am struggling with that I
> hope you could give me some insight on.
> 
> I'm using ActivePerl to create an automated build process.  Part of
> the process is setting the LIB, INCLUDE, PATH, SOURCE variables from
> within the Perl script and then using a system call to invoke
> MSDEV.EXE using the /USEENV option.  It looks like the process the
> Perl script is running in is setting the variables I need, but MSDEV
> is not finding them.  If I manually set the same values within the DOS
> console and then run my Perl script, MSDEV finds the variables.

This makes me suspect the latter; which is definitely not what you want
in this case. MSDEV.EXE will receive the environment given it by the
perl process, rather than the default environment. In addition, new
console windows you open *will* receive the default environment, so they
will get the values for LIB etc. you have specified... not terribly
useful. Try using %ENV.

> I'm working on Windows XP, so I'm not sure if this might be the issue,
> but it behaves as if MSDEV is not looking at the process that the Perl
> script is running in, but is looking at it's parent for the
                                        GRR ^
> environment variables.

This is unlikely. Processes don't have parents under windows (except
under certain restricted situations).

> Is there any way of setting environment variables within the 'parent'
> DOS process from the PErl script?

No.

Ben


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

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 6523
***************************************


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