[24098] in Perl-Users-Digest
Perl-Users Digest, Issue: 6292 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 22 21:05:46 2004
Date: Mon, 22 Mar 2004 18:05:05 -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 Mon, 22 Mar 2004 Volume: 10 Number: 6292
Today's topics:
Attempt to free unrefferenced scalar: <jcanfield@tshmail.com>
Re: Attempt to free unrefferenced scalar: <tadmc@augustmail.com>
Re: Attempt to free unrefferenced scalar: <jcanfield@tshmail.com>
BigInt.pm acting dumb, or is it me? (Steve The Geek)
Re: Building Perl with Open Watcom <nospam-abuse@ilyaz.org>
emacs cperl-mode: indentation and so on... <siscus@cidddis.es>
Re: emacs cperl-mode: indentation and so on... <me@privacy.net>
Re: getch <bart.lateur@pandora.be>
Invalid Class String - Win32::OLE (Prad)
Matching between blank lines <noone@nowhere.com>
Re: Matching between blank lines <noreply@gunnar.cc>
Re: Perl upgraded = problem resurfacing (Grant)
Re: Redirect problem (David Efflandt)
Re: scope again <remorse@partners.org>
Re: scope again <invalid-email@rochester.rr.com>
Re: selfmade scripts <noreply@gunnar.cc>
Re: Truncating several lines of text into one line and <remorse@partners.org>
Re: Truncating several lines of text into one line and (v796)
Re: Truncating several lines of text into one line and <tadmc@augustmail.com>
Re: Truncating several lines of text into one line and <ittyspam@yahoo.com>
Re: using a variable as STDIN for an external program <dwall@fastmail.fm>
Re: working example File::Taill <remorse@partners.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 Mar 2004 15:01:12 -0600
From: "Jim Canfield" <jcanfield@tshmail.com>
Subject: Attempt to free unrefferenced scalar:
Message-Id: <105ul0p2pa4tcf5@corp.supernews.com>
Greetings,
I'm still learning perl so I hope someone can axplain this to me. I'm
getting the following error:
Attempt to free unrefferenced scalar: SV 0x1e20874
This happens only when I try to add some MIME::Lite code to send a simple
e-mail. Like so...
#test simple e-mail
my $mail = MIME::Lite->new(
From =>'test@myhost.com',
To =>'fake@fake.com',
Subject =>'test message',
Data =>"test"
);
$mail->send("smtp", 'smtp.fake.net');
This is being added to the bottom of code that looks like this..
# Connect to the database
my $dbh = DBI->connect( "dbi:$driver:database=$db;$host",
"$username",
"$password",
{
RaiseError => 1,
AutoCommit => 0
}
)or die "Can't connect to Mysql database: $DBI::errstr\n";
#Get hash
my $set = $dbh->selectall_hashref("SELECT...."key");
$dbh->disconnect();
What am I missing? The two part are totally unrelated, howver if I comment
out the $mail send line the entire script runs fine...well except for
sending an e-mail.
Thanks.
------------------------------
Date: Mon, 22 Mar 2004 15:50:25 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Attempt to free unrefferenced scalar:
Message-Id: <slrnc5unt1.9qg.tadmc@magna.augustmail.com>
Jim Canfield <jcanfield@tshmail.com> wrote:
> Attempt to free unrefferenced scalar: SV 0x1e20874
Please do not re-type warning messages.
Use copy/paste or your editor's "import" function rather than
attempting to type in your messages. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
Like this one.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 22 Mar 2004 16:57:43 -0600
From: "Jim Canfield" <jcanfield@tshmail.com>
Subject: Re: Attempt to free unrefferenced scalar:
Message-Id: <105urr8i1kdv98c@corp.supernews.com>
> Please do not re-type warning messages.
>
Thanks, I appreciate the constructive criticism, but it gets me no closer to
figuring out this crazy error. Can anyone at least tell me if there is a
module or something that can output which scalar might be in question? Or
what the address means?
------------------------------
Date: 22 Mar 2004 11:11:29 -0800
From: slkleine@hotmail.com (Steve The Geek)
Subject: BigInt.pm acting dumb, or is it me?
Message-Id: <863f122c.0403221111.813f7a9@posting.google.com>
Environment: Win32 with Open Perl IDE, ActiveState Perl latest stable
rev.
relevant modules: Net::SNMP, Math:BigInt
I'm attempting to use Net::SNMP to alter the system.sysLocation.0 OID
on all our servers.
When compiling, Net::SNMP gets to BigInt.pm and hangs there, devouring
all the memory and processor it can until forced termination.
I've uninstalled & reinstalled Math::Bigint from two different
sources, but no joy.
The communications log from OpenPerl IDE looks like this (will wrap):
20040322133223417: Dispatching DM_START_REQ: DEC_OK
20040322133226161: Receiving DM_MODULE_LOADED_REP: C:\Documents and
Settings\All Users\Start Menu\Programs\Perl\perl5db.pl
20040322133226502: Receiving DM_MODULE_LOADED_REP:
C:\Perl\lib\overload.pm
20040322133226552: Receiving DM_MODULE_LOADED_REP:
C:\Perl\lib\constant.pm
20040322133226682: Receiving DM_MODULE_LOADED_REP:
C:\Perl\lib\integer.pm
20040322133226732: Receiving DM_MODULE_LOADED_REP:
C:\Perl\lib\Math\BigInt.pm
Even reducing the script to this snippet hangs on compile:
use strict;
use warnings;
use Net::SNMP;
And here's the kicker -- that small snippet works at runtime!
Any explanation for this admittedly weird behavior?
Steve the (512MB is not enough) Geek
------------------------------
Date: Mon, 22 Mar 2004 22:23:31 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Building Perl with Open Watcom
Message-Id: <c3np13$agb$1@agate.berkeley.edu>
I realized that it makes sense to update the Newsgroups line too late;
so the only purpose of this post is to cross-post to c.l.p.m.
I wrote in article <c3noc0$a7e$1@agate.berkeley.edu>:
> [A complimentary Cc of this posting was NOT [per weedlist] sent to
> Mat Nieuwenhoven
> <mnieuw@don'tincludethis@zap.a2000.nl>], who wrote in article <zavrhjmncnay.huz5lh0.pminews@news.text.chello.nl>:
> > :>be a problem. However, I'm pretty sure that without EMX most of
> > :>functionality will be severely limited; I never saw Watcom, but my
> > :>impression is that its RTL is extremely limited and comes nowhere
> > :>close to POSIX.
> > :>
> > :>Most probably, one can restore about 50% of lost functionality using
> > :>Win*-specific branches, but this is going to be a lot of work.
> >
> > I accept your authority on Perl, I've never even looked at it. But can you
> > please give some details on what you think is missing in the Watcom RTL?
>
> As I said, this is only an uneducated guesswork on my side; I meant
> all the POSIXish stuff which is AFAIK missing in VAC: what I can
> immediately remember is exec() (which is used much more frequently
> than fork()), an ability to treat a socket as a file descriptor, and
> some minor-but-tedious stuff auto-translation of /dev/tty and
> /dev/null, etc. Doing tell()/seek() on text files is a problem with
> many compilers as well. "Reliable" treatment of ^Z in text files?
> sbrk() (optional for perl, but may improve functionality a lot)?
> Reliable command-line argument quoting/dequoting and globbing (so that
> arguments to spawnve() correspond 1-to-1 to argv[] array)? wait()?
> alarm()? select() on many kinds of file descriptors?
>
> The fact is that Perl is (together with other uses) a glue to system's
> functionality, and POSIX is a very convenient common denominator. So
> a lot of available Perl software assumes that the current perl
> executable is capable of POSIXish behaviour.
>
> Perl build process is very configurable, and is able to auto-detect
> most of capabilities of the current build environment. It should not
> be hard to compile a build of perl with any (no matter how stupid)
> compiler. The problems with the build will be twofold:
>
> a) as I explained before, a lot of Perl scripts will not work with
> this build.
>
> b) *a lot* of stuff in the test suite will fail, and it will be very
> hard to distinguish the bugs of the build environment (worsened by
> the possible bugs in the auto-detection phase) versus the
> restrictions of the build environment not taken into account by
> the test suite.
>
> To fix b), one needs to sifter through all the test suite failures,
> and update the test suite to take into account all the new
> restrictions coming with this new build environment.
>
> To fix a) one needs to sifter through each new Perl script and
> "improve" it by changing all the "POSIXish" stuff (like "/dev/null")
> to the "portable" one (like File::Spec->null(). I put "improve" in
> quotes since this *is* an improvement in the portability of the
> script, but is a step back in maintainability of the script due to
> increase in the amount of code).
>
> From my POV, it is much easier to fix this on the level of perl guts;
> this is the design goal of my OS/2 port; e.g., it uses a Bourne-syntax
> shell for those system()/exec()s which require shell, as opposed to
> %COMSPEC%.
>
> > From what you say, it appears that a Win32 based Perl is missing 50%
> > from an EMX one?
>
> The largest gap of (non Cygwin) perls on Window is a botched emulation
> of fork() - which EMX does almost perfectly. BTW, the 50% number I
> gave was related to "easy to convert from Win32 branches"; the
> remaining 50% is technically possible, but (I think) would require
> some new code.
>
> > Does this mean Perl for Win32 is created with Cygwin?
>
> Any way you would like (but I did not hear about the Watcom branch).
>
> > If it is created with MS tools, Watcom should be able to build the
> > Win32 version at least without much problems.
>
> I trust your judgement on this (w.r.t. to Win32 port).
>
> Hope this helps,
> Ilya
------------------------------
Date: Mon, 22 Mar 2004 22:06:47 GMT
From: Cedros <siscus@cidddis.es>
Subject: emacs cperl-mode: indentation and so on...
Message-Id: <k7ou50tr4ukkcdjokktrckr7j51a09kcd5@4ax.com>
hi,
I'm learning perl and I want to use emacs and his cperl mode. I have
some problems:
- when I open a perl program, emacs run perl mode, not cperl. How can I
do to have cperl as default?
- also if I run cperl with M-x cperl-mode, I'm not able to have a decent
indentation: if I press enter, emacs always return to first column next
line. What are keys to have a decent indentation? (in VHDL-mode I use
M-q but here it seems it doesn't function.
Thanks in advance
Cedros
------------------------------
Date: 22 Mar 2004 22:16:44 GMT
From: James Keasley <me@privacy.net>
Subject: Re: emacs cperl-mode: indentation and so on...
Message-Id: <slrnc5upeb.7me.me@athena.homeric.co.uk>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-03-22, Cedros <siscus@cidddis.es> wrote:
> hi,
>
> I'm learning perl and I want to use emacs and his cperl mode. I have
> some problems:
>
> - when I open a perl program, emacs run perl mode, not cperl. How can I
> do to have cperl as default?
Dumping the following lisp into your ~/.emacs file will tell
emacs to use Cperl-mode instead of perl-mode, and turns on a
couple of the other handy functions cperl-mode keeps up its sleeve.
;; Use Cperl-mode in preference to perl-mode (added 2003/11/27)
(defun modify-alist (alist-symbol key value &optional search-cdr)
(let ((alist (symbol-value alist-symbol)))
(while alist
(if (eq (if search-cdr
(cdr (car alist))
(car (car alist))) key)
(setcdr (car alist) value)
(setq alist (cdr alist))))))
(modify-alist 'interpreter-mode-alist 'perl-mode 'cperl-mode t)
(modify-alist 'auto-mode-alist 'perl-mode 'cperl-mode t)
;; set cperl-mode to use electric parens and keywords
(setq cperl-electric-parens t)
(setq cperl-electric-keywords t)
> - also if I run cperl with M-x cperl-mode, I'm not able to have a decent
> indentation: if I press enter, emacs always return to first column next
> line. What are keys to have a decent indentation? (in VHDL-mode I use
> M-q but here it seems it doesn't function.
Not sure about this, it usually seems to "just work" for me, someone
else will come along and enlighten you on this, I'm sure
- --
James jamesk[at]homeric[dot]co[dot]uk
'No, `Eureka' is Greek for `This bath is too hot.'' -- Dr. Who
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAX2XLqfSmHkD6LvoRApymAJ9s5CJ0MFoHdxaKnid92DsxCdbBawCfbEdV
W2sTyzOiWnPMvbFV5dNf09c=
=SVhg
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 22 Mar 2004 19:05:16 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: getch
Message-Id: <j5eu5091cd75fehhscal3t1ejli4m4lhtu@4ax.com>
toylet wrote:
>Which perl function would wait for a keypress and return its EBCDIC code?
Assuming you are on an EBCDIC platform... all you want is getch(). Or
look up the module Term::ReadKey, it comes with Perl IIRC.
--
Bart.
------------------------------
Date: 22 Mar 2004 15:15:28 -0800
From: psethi@siteindia.com (Prad)
Subject: Invalid Class String - Win32::OLE
Message-Id: <c54121d6.0403221515.d091ac2@posting.google.com>
Hi,
I am trying to instantiate a COM component using Win32::OLE. Here is
what I am doing.
use Win32::OLE;
my $Class = "CaliberRM.CaliberServerFactory";
my $objCaliberServerFactory = new Win32::OLE( $Class) || die
"Can not create a '$Class' object.\n";
}
my $initClass = "caliberrm.Initializer";
my $objInit= new Win32::OLE( $initClass) || die "Can not
create a '$initClass' object.\n";
It works absolute fine for the first class, but gives me "Invalid
class string" for the second one and dies.
If I try to instantiate the same using Visual Basic, it works okay for
ex :
Dim objInitializer As New caliberrm.Initializer
Dim objServerFact As New CaliberServerFactory
What am I missing here ?
Thanks in advance
-Pradeep
------------------------------
Date: Mon, 22 Mar 2004 22:49:52 GMT
From: "gibbering poster" <noone@nowhere.com>
Subject: Matching between blank lines
Message-Id: <k4K7c.13441$K85.6190@newssvr27.news.prodigy.com>
Sorry in advance if I missed the part of the fm that I was supposed to
read...
My question is: How do I take a multi-line string, and match the data
between blank lines?
Take the following:
__BEGIN-STRING__
blahblahblahblah
1234: --dfs-ffjlkj
THIS IS WHAT I WANT TO MATCH
JUnkjunkjunk
12o3iu
__END-STRING__
How would I match the text between the 2 blank with a regular
expression? I.e. 'THIS IS WHAT I WANT TO MATCH' ?
I tried /^$(.*?)^$/m ....
Thanks in advance for help
------------------------------
Date: Tue, 23 Mar 2004 00:26:24 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Matching between blank lines
Message-Id: <c3nspd$29cso1$1@ID-184292.news.uni-berlin.de>
gibbering poster wrote:
> How would I match the text between the 2 blank with a regular
> expression? I.e. 'THIS IS WHAT I WANT TO MATCH' ?
>
> I tried /^$(.*?)^$/m ....
Try
/\n\n(.*?)\n\n/s
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 22 Mar 2004 17:24:00 -0800
From: emailgrant123@yahoo.com (Grant)
Subject: Re: Perl upgraded = problem resurfacing
Message-Id: <1c9d8b45.0403221724.2dfea72b@posting.google.com>
Roel van der Steen <roel-perl@st2x.net> wrote in message news:<slrnc5mdl1.284.roel-perl@localhost.localdomain>...
> On Fri, 19 Mar 2004 at 17:43 GMT, Grant <tonearm@email.com> wrote:
> > I suppose I don't know that it is totally blank for sure, although the
> > If the above code should
> > still be working to correctly route a blank response, can anyone
> > suggest code that would check the response for something specific that
> > should be there (like "<?xml") and decide what to do based on that?
>
> What about (untested):
>
> if ($response =~ /^<\?xml/ ) {
> # *XML::Simple processing*
> }
> else {
> # *processing*
> }
Thanks a lot Roel and Anno for the info.
Roel, your code works like a charm and has solved my problem! It
turns out I'm getting the following response when "<?xml" isn't in it:
500 Can't connect to api.site.com:443 (Bad hostname 'api.site.com')
For some reason, this was being sent to "XML::Simple processing" for a
crash until Perl was upgraded (as outlined in my original post).
One more thing: The "<?xml" characters will always be at the very
beginning of the response. Is there a better way to write:
if ($response =~ /^<\?xml/ ) {
knowing that? Thanks again!
- Grant
------------------------------
Date: Mon, 22 Mar 2004 19:36:34 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Redirect problem
Message-Id: <slrnc5ug21.5r7.efflandt@typhoon.xnet.com>
On Mon, 22 Mar 2004, Tigerhillside
<Tigerhillsideremove@removenetscape.net> wrote:
> In comp.lang.perl.misc, efflandt@xnet.com (David Efflandt), I
> read and responded
>
>>If you read 'perldoc CGI', it says "relative links may not work
>>correctly...The solution to this is to use the full URL..." Relative
>>internal links may be considered insecure for a secure server.
>
> As I said, I tried all of the variations, none of them worked. I
> did read the docs and so used the full URI at first. When that
> did not work I thought that maybe it did not see that the
> redirect was to the same server and saw that it was insecure so I
> tried various relative links. I figured that "ma not" could also
> mean "may" and that an internal redirect may be considered
> secure.
When you say full URI, do you mean a full URL beginning "https://", or
just a URI path? I have had trouble with redirect() in some CGI version
escaping things that broke the redirect. So you might try (make sure you
do not print anything else):
print "Location: https://hostname.domain/path/file\n\n";
--
David Efflandt - All spam ignored http://www.de-srv.com/
------------------------------
Date: Mon, 22 Mar 2004 14:44:39 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: scope again
Message-Id: <remorse-FE0A55.14443922032004@plato.harvard.edu>
In article <daw7c.33073$%06.21244@newsread2.news.pas.earthlink.net>,
Joe <mail@annuna.com> wrote:
> All I want to know is why $space dosn't act global in the Space package.
If this is _really_ what you are asking, then I think the issue might be
a confusion between lexical and package scope.
You might want to look at the 'our' keyword.
HTH,
Ricky
------------------------------
Date: Tue, 23 Mar 2004 01:33:02 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: scope again
Message-Id: <405F93C1.8020106@rochester.rr.com>
John W. Krahn wrote:
> Bob Walton wrote:
...
>>>print "$space->{loc}"; < -won't print these data mbembers.
>>>
>>--------^-------------^
>>Inside quotes, the variable $space will be interpolated. If $space
>>contains the string "Pluto", you would get:
>>
>> Pluto->{loc}
>>
>>printed. Interpolation does not evaluate operators.
>>
>
> Are you sure about that Bob? It's very easy to test:
>
> $ perl -le'my $space = q(Pluto); print "$space->{loc}";'
>
> $ perl -le'my $space = { loc => 888 }; print "$space->{loc}";'
> 888
...
> John
Hmmm...Yes, thanks, I see that you are correct. I should have tested.
I see it is documented, too, although not super clearly:
[from perlop]
"Note also that the interpolation code needs to make a decision on
where the interpolated scalar ends. For instance, whether "a $b -> {c}"
really means:
"a " . $b . " -> {c}";
or:
"a " . $b -> {c};
Most of the time, the longest possible text that does not include
spaces between components and which contains matching braces or
brackets. because the outcome may be determined by voting based on
heuristic estimators, the result is not strictly predictable.
Fortunately, it's usually correct for ambiguous cases."
Sounds like it might not be the best thing to actually count on.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Mon, 22 Mar 2004 20:49:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: selfmade scripts
Message-Id: <c3ng1f$296t4h$1@ID-184292.news.uni-berlin.de>
luc wrote:
> ... I cant put it on my site's server ...
Change web host!!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 22 Mar 2004 14:26:16 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: Truncating several lines of text into one line and putting in scalar
Message-Id: <remorse-30502E.14261522032004@plato.harvard.edu>
In article <c3iifv$2ep$2@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
>
> > Maybe you would prefer the canonical canonicalisation of whitespace:
>
> Can we canonicalize that term, please?
Probably about as soon as we can agree on color vs. colour, etc.
As I recall it, use of the 's' in this suffix is standard in British
English, while the 'z' is indicative of American English.
Ricky
------------------------------
Date: 22 Mar 2004 12:52:55 -0800
From: vicky7909@rediffmail.com (v796)
Subject: Re: Truncating several lines of text into one line and putting in scalar
Message-Id: <49f90fb9.0403221252.164b2ccf@posting.google.com>
Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040319122241.U21521@dishwasher.cs.rpi.edu>...
> On Fri, 19 Mar 2004, v796 wrote:
>
> > Hi,
> >
> > I have text across several lines in a scalar like this:
> >
> > ddd
> > .
> > <blank line>
> > <blank line>
> > Hello there how are you?
> > continues
> > text
> > more etext
> > text ends
> >
> > The above text is in a scalar variable. I need to get the text (split
> > by newlines) into a scalar like this
> > $text = "ddd . Hello there how are you? continues text more etext text
> > ends";
> >
> > Notice that the first letter of every line is preceded by one space in
> > $text. Also all the blank lines are deleted. And now it is like it was
> > originally in one line i.e. without newlines '\n'.
> >
> > How can this be done?
> >
>
>
> As someone here said recently in another post...
>
> What have you tried so far?
> What didn't work?
> When is the homework assignment due?
>
> Paul Lalli
Hello Paul,
My advice to you is: Don't ever go for jury duty. Since if you do
you'll end up misjudging someone.
Though I needn't defend myself, cause I know the truth and my
conscience is clear, I am *not* going to take this false accusation
lying down. I understand what you mean by homework assignment. I
clearly do. Just because I am new to Perl and you aren't and you think
that this is an assignment doesn't mean it is.
If you don't want to help fine, but don't go about accusing people.
Cause do not forget one day you didn't know Perl too! Unless you born
knowing it!
So here is what I tried, $content =~ s/\n/\s/g; But it doesn't work.
Gives s in the middle...But from the tutorial I read it should work
cause it globally substitutes newline with a space.
You may be very knowledgeable but you are definitely very not nice.
And if you want to be judgemental look around alt. in your spare time.
Sincerely,
v796.
------------------------------
Date: Mon, 22 Mar 2004 15:46:38 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Truncating several lines of text into one line and putting in scalar
Message-Id: <slrnc5unlu.9qg.tadmc@magna.augustmail.com>
Paul Lalli <ittyspam@yahoo.com> wrote:
> On Mon, 22 Mar 2004, v796 wrote:
>> Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040319122241.U21521@dishwasher.cs.rpi.edu>...
>> > On Fri, 19 Mar 2004, v796 wrote:
>> So here is what I tried, $content =~ s/\n/\s/g; But it doesn't work.
> It doesn't work because the replacement portion of s///; is supposed to be
> a string, not a regular expression.
> if you want to replace all newlines
> with ordinary space characters, do like so:
>
> s/\n/ /g;
>
> If, however, you want to condense multiple consecutive newlines into a
> single space character, you might want this instead:
>
> s/\n+/ g;
That was supposed to be:
s/\n+/ /g;
but this will be faster:
tr/\n/ /s;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 22 Mar 2004 16:14:35 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Truncating several lines of text into one line and putting in scalar
Message-Id: <20040322161029.Q21521@dishwasher.cs.rpi.edu>
On Mon, 22 Mar 2004, v796 wrote:
> Paul Lalli <ittyspam@yahoo.com> wrote in message news:<20040319122241.U21521@dishwasher.cs.rpi.edu>...
> > On Fri, 19 Mar 2004, v796 wrote:
> >
> > > Hi,
> > >
> > > I have text across several lines in a scalar like this:
> > >
> > > ddd
> > > .
> > > <blank line>
> > > <blank line>
> > > Hello there how are you?
> > > continues
> > > text
> > > more etext
> > > text ends
> > >
> > > The above text is in a scalar variable. I need to get the text (split
> > > by newlines) into a scalar like this
> > > $text = "ddd . Hello there how are you? continues text more etext text
> > > ends";
> > >
> > > Notice that the first letter of every line is preceded by one space in
> > > $text. Also all the blank lines are deleted. And now it is like it was
> > > originally in one line i.e. without newlines '\n'.
> > >
> > > How can this be done?
> > >
> >
> >
> > As someone here said recently in another post...
> >
> > What have you tried so far?
> > What didn't work?
> > When is the homework assignment due?
> >
> > Paul Lalli
>
> Hello Paul,
> My advice to you is: Don't ever go for jury duty. Since if you do
> you'll end up misjudging someone.
>
> Though I needn't defend myself, cause I know the truth and my
> conscience is clear, I am *not* going to take this false accusation
> lying down. I understand what you mean by homework assignment. I
> clearly do. Just because I am new to Perl and you aren't and you think
> that this is an assignment doesn't mean it is.
> If you don't want to help fine, but don't go about accusing people.
> Cause do not forget one day you didn't know Perl too! Unless you born
> knowing it!
>
You need to calm down. A lot. What I said was said in jest, the reason
being that the problem you describe sounds A LOT like a standard "just
beginning to learn Perl" homework assignment. (I know because I used to
teach Perl at a college). If you can't take at least a little bit of
humor, *you* will not get far either. Now onto the issue at hand...
> So here is what I tried, $content =~ s/\n/\s/g; But it doesn't work.
> Gives s in the middle...But from the tutorial I read it should work
> cause it globally substitutes newline with a space.
It doesn't work because the replacement portion of s///; is supposed to be
a string, not a regular expression. You can't use regular expression
syntax in the replacement. Therefore, if you want to replace all newlines
with ordinary space characters, do like so:
s/\n/ /g;
If, however, you want to condense multiple consecutive newlines into a
single space character, you might want this instead:
s/\n+/ g;
Paul Lalli
------------------------------
Date: Mon, 22 Mar 2004 19:43:12 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: using a variable as STDIN for an external program
Message-Id: <Xns94B495BDCB9A5dkwwashere@216.168.3.30>
C3 previously said:
> I'd like to call an external program through perl, but I need to
> redirect a variable in my perl program, to STDIN of the external
> program. I also need to read the output of the external program
> (one line only).
and later said:
> Nevermind, I fixed it.
For the benefit of people who may have a similar problem, how about posting
some code that shows HOW you fixed it?
--
David Wall
------------------------------
Date: Mon, 22 Mar 2004 15:11:09 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: working example File::Taill
Message-Id: <remorse-BF65F1.15110922032004@plato.harvard.edu>
In article <c4b60ce1.0403220605.585476d7@posting.google.com>,
google@milbaugh.com (GreenLight) wrote:
> Richard Morse <remorse@partners.org> wrote in message
> news:<remorse-D994B9.15232619032004@plato.harvard.edu>...
> > It's better not to pre-declare your variables -- declare them just where
> > you'd need them...
> >
> > Ricky
>
> Just in case there are some impressionable young newbies out there 8^)
> this bit of "advice" is quite poor -- in fact, using "strict" and
> pre-declaring your variables is very good programming practice.
I apologize for the poor wording -- as others have already pointed out,
what I was hoping to say was that it's not a useful practice to declare
variables far in advance of where you need them.
Ricky
------------------------------
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 6292
***************************************