[27888] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9252 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 2 21:06:08 2006

Date: Fri, 2 Jun 2006 18:05:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 2 Jun 2006     Volume: 10 Number: 9252

Today's topics:
    Re: Best way to output literal strings as UTF-8 ? <bart@nijlen.com>
    Re: foreach @list ( (1,2), (5,6) ){ ... } <bol@adv.magwien.gv.at>
    Re: foreach @list ( (1,2), (5,6) ){ ... } <mritty@gmail.com>
        Howto share filehandles between threads? <riderjunk@NOSPAMdls.net>
    Re: LV & BM values <nospam-abuse@ilyaz.org>
    Re: LV & BM values <bol@adv.magwien.gv.at>
    Re: nested quantifier or unrecognized escape error <peace.is.our.profession@gmx.de>
    Re: perl TK related (manupulating the output text area) <mritty@gmail.com>
    Re: perl TK related (manupulating the output text area) <brian.raven@aems.net>
    Re: Problems of Perl program with Spreadsheet::ParseExc <Angel.Gerdzhikov@googlemail.com>
        Regexp help. <my_email_address_is_in_my_sig@privacy.net>
    Re: Regexp help. <peace.is.our.profession@gmx.de>
    Re: Way to return a file handle from a XSUB? <sherm@Sherm-Pendleys-Computer.local>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 2 Jun 2006 04:09:53 -0700
From: "Bart Van der Donck" <bart@nijlen.com>
Subject: Re: Best way to output literal strings as UTF-8 ?
Message-Id: <1149246593.434492.168100@f6g2000cwb.googlegroups.com>

Yohan N. Leder wrote:

> Using Perl 5.8.8, I'm trying to found the best way to support UTF-8
> everywhere about outputted literal strings (from source code) toward
> generated UTF-8 HTML in browser.
>
> I've done this :
> - Saved source code (containing the literal strings) as UTF-8
> - Added a "use utf8;" line in code
> - Added a "binmode(STDOUT, ":utf8");" line in code
>
> [...]

I would counsel to add the following:
- Set the charset of the output stream to utf8
- Set the webpage's <meta http-equiv="Content-Type"> to utf8

Like:

  #!/usr/bin/perl
  use strict;
  use warnings;
  print <<'HTML'
  Content-Type: text/html; charset=utf-8

  <html>
  <head>
  <meta http-equiv="Content-Type"
        content="text/html; charset=utf-8">
  </head>
  <body>pretty sure we are in utf-8 now</body>
  </html> 
  HTML 

Hope this helps,

-- 
 Bart



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

Date: Fri, 2 Jun 2006 15:27:57 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: foreach @list ( (1,2), (5,6) ){ ... }
Message-Id: <1149254877.805256@proxy.dienste.wien.at>

Mumia W.:

> BTW, avoid making $a and $b lexical.

Why? As long as sort {} isn't used...

But wouldn't it be a nice idea to issue a warning
message in this case (with 'use warnings')?

Greetings, Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




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

Date: 2 Jun 2006 06:52:56 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: foreach @list ( (1,2), (5,6) ){ ... }
Message-Id: <1149256376.788405.61670@i40g2000cwc.googlegroups.com>

Ferry Bolhar wrote:
> Mumia W.:
>
> > BTW, avoid making $a and $b lexical.
>
> Why? As long as sort {} isn't used...

That advice should really be "Avoid using $a and $b except in a sort
subroutine".  $a and $b are special. They are not subject to
strictures:

#!/usr/bin/perl
use strict;
use warnings;

sub foo {
    print "A: $a, B: $b\n";
}

my ($a, $b) = (5, 10);

foo();
__END__
$ perl ab.pl
Name "main::a" used only once: possible typo at ab.pl line 6.
Name "main::b" used only once: possible typo at ab.pl line 6.
Use of uninitialized value in concatenation (.) or string at ab.pl line
6.
Use of uninitialized value in concatenation (.) or string at ab.pl line
6.
A: , B:

> But wouldn't it be a nice idea to issue a warning
> message in this case (with 'use warnings')?

As you can see, there are plenty of warnings for certain cases of
accidental $main::a and $main::b usage.  What warning, exactly, are you
suggesting be added?

Paul Lalli



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

Date: Fri, 02 Jun 2006 08:23:07 -0500
From: Sako <riderjunk@NOSPAMdls.net>
Subject: Howto share filehandles between threads?
Message-Id: <F-CdnSvZxNkhph3ZRVn-tg@dls.net>

I am trying to teach myself perl by writing a program I've been meaning 
to implement, so I am pretty green in perl. I'm having problems sharing 
filehandles opened by a thread - been RTFM for a few days, but am having 
no luck.

I am attempting to write a threaded server program that listens on a 
socket for requests, then passes the socket's filehandle to an event 
processor routine, while the listener thread keeps on listening. 
However, I cannot seem to be able to successfully pass the filehandle 
from the listener thread to the event handler.

For testing purposes, I've tried to get the logic down using a thread to 
open a filehandle and pass it back to the non-threaded routine as follows:

--------- start ------------
#!/usr/bin/perl

     use threads;
     use threads::shared;

     my $FH : shared;

     threads->new(sub {
         open($LFH,"< /tmp/junk") || die $!;
         $FH=$LFH;
         print "[$FH]\n";
         #while (<$LFH>) {print "> $_";}
     })->join;

     print "[$FH]\n";
     while (<$FH>) {print "> $_";}

---------- end -------------

Running it gives:
"thread failed to start: Invalid value for shared scalar at ./x.pl line 10."

Any help on how to share a filehandle opened in a thread would be 
GREATLY appreciated.

TIA


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

Date: Fri, 2 Jun 2006 11:10:08 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: LV & BM values
Message-Id: <e5p6ag$b1$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Ferry Bolhar
<bol@adv.magwien.gv.at>], who wrote in article <1149242523.417334@proxy.dienste.wien.at>:
> Hi Ilya,
> 
> Many thanks for your help and your patience.
> 
> >perl -MO=Terse -ce "print index $_, q(ab)"
> 
> Could you explain in short terms what a BM actually IS?

Did you look Boyer-Moore on Wikipedia?

> how and when it will be created/used?

Whenever deemed appropiate (in a particular version of Perl).  Use the source.

> And concerning LVs - I know that there
> are some
> 
> functions which can be used on the left side of an assignment (pos, vec,
> substr). But I can't understand
> 
> why there is a special kind of SV for this.

So that

 sub foo { $_[0] = s/.../.../g }
 foo(substr "foo", bar, baz)

works.

> BTW: does XS support LVALUE functions?

This question does not make any sense.  XS is C + declarations of
Perl-to-C interface.  Perl is written in C.  Thus everything which
Perl does is available in .xs files.  (But some Perl internals are
documented, some not; thus there is/isn't a promise that they are
version-independent.)

Hope this helps,
Ilya


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

Date: Fri, 2 Jun 2006 15:17:10 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Re: LV & BM values
Message-Id: <1149254230.912666@proxy.dienste.wien.at>

Ilya Zakharevich:

> So that
>
>  sub foo { $_[0] = s/.../.../g }
>  foo(substr "foo", bar, baz)
>
> works.

When running this code (replacing '=' with '=~', writing 's/o/u/g'
and replacing 'bar and 'baz' with numerical literals 1 and 2), I get

Modification of a read-only value attempted

What did you want to prove thereby?

>> BTW: does XS support LVALUE functions?
>
> This question does not make any sense.  XS is C + declarations of
> Perl-to-C interface.  Perl is written in C.  Thus everything which
> Perl does is available in .xs files.

As we know meanwhile, this isn't always true, especially
not for things Perl does in the compiling phase.

Perhaps my question was malformed: when writing a
XS function which I want to be callable in lvalue context,
are there some hints I should be aware? For example,
how a XS function can find out that it was called as
lvalue?

Greetings, Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




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

Date: Fri, 02 Jun 2006 12:38:24 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: nested quantifier or unrecognized escape error
Message-Id: <e5p4m1$fr2$1@mlucom4.urz.uni-halle.de>

Thus spoke Nick of course (on 2006-06-02 11:43):

> Mirco Wahab wrote:
>>   print "match {". $pat ."}\n";
> 
> I know this has nothing to do with the original problem but isn't it
> more readable as...
> 
>    print "match{$pat}\n";

Of course it would ...

But I'm shuddering on inserting
block context delimiters _this way_
into brackets when interpolation
is wanted

    print "match {".    $pat . "}\n";
    print "match {". do{$pat}. "}\n";

So its just a matter of taste what
means 'less ambiguity' for an
'beginner==>intermediate' ;-)

Regards

Mirco


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

Date: 2 Jun 2006 04:39:27 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: perl TK related (manupulating the output text area)
Message-Id: <1149248367.568789.287240@c74g2000cwc.googlegroups.com>

king wrote:
> #!\c\perl\bin
> use Tk;
>
> my $mw = new MainWindow; # Main Window
>
> my $frm_name = $mw -> Frame() -> pack();
> my $lab = $frm_name -> Label(-text=>"Name:") -> pack();
> my $ent = $frm_name -> Entry() -> pack();
>
> my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button) ->
> pack();
> #Text Area
> my $txt = $mw -> Text(-width=>50, -height=>30) -> pack();
>
> MainLoop;
>
> #This function will be executed when the button is pushed
> sub push_button {
> 	my $name = $ent -> get();
> 	$txt -> insert('end',"Hello, $name.");
> }
>
> 1.as soon as i run this script
> a window opens
> But the cursor is not on the name block
> Question- Can it be possible that as soon as the window opens the
> cursor should be present in the name block.

Add the line:
$ent->focus();
right before MainLoop;

> again
> 2. suppose once i typed a name,it will show up with hellow then the
> $name.
> but in the same window if I again give some other name in the name
> block,
> the hellow $ name is coming next to the previous test messege in the
> text area.
> Question
> Each time I give a input and then enter button push me the only text
> present there should be hellow and the recent name entered.
> Can it be possible to do that.

Yes.  Just delete the text that's currently in the box right before you
insert the new text.  Look up the widget's delete() method at
http://search.cpan.org/~ni-s/Tk-804.027/pod/Text.pod#WIDGET_METHODS

Paul Lalli



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

Date: Fri, 02 Jun 2006 12:56:12 +0100
From: Brian Raven <brian.raven@aems.net>
Subject: Re: perl TK related (manupulating the output text area)
Message-Id: <vtk67zai03.fsf@lxdevws06.admin.liffe.com>

"king" <hara.acharya@gmail.com> writes:

> #!\c\perl\bin

Missing "use strict; use warnings;"

> use Tk;
>
> my $mw = new MainWindow; # Main Window
>
> my $frm_name = $mw -> Frame() -> pack();
> my $lab = $frm_name -> Label(-text=>"Name:") -> pack();
> my $ent = $frm_name -> Entry() -> pack();
>
> my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button) ->
> pack();
> #Text Area
> my $txt = $mw -> Text(-width=>50, -height=>30) -> pack();
>
> MainLoop;
>
> #This function will be executed when the button is pushed
> sub push_button {
> 	my $name = $ent -> get();
> 	$txt -> insert('end',"Hello, $name.");
> }
>
> 1.as soon as i run this script
> a window opens
> But the cursor is not on the name block
> Question- Can it be possible that as soon as the window opens the
> cursor should be present in the name block.

See 'perldoc Tk::focus'

>
> again
> 2. suppose once i typed a name,it will show up with hellow then the
> $name.
> but in the same window if I again give some other name in the name
> block,
> the hellow $ name is coming next to the previous test messege in the
> text area.

Well, that is what you told it to do.

> Question
> Each time I give a input and then enter button push me the only text
> present there should be hellow and the recent name entered.
> Can it be possible to do that.
>

Then you have to delete what was already there before inserting a new
string. Look for the delete function in 'perldoc Tk::Text'.

HTH

-- 
Brian Raven

That which hits the fan tends to get flung in all directions.
             -- Larry Wall in <199809091801.LAA15194@wall.org>


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

Date: 2 Jun 2006 05:21:20 -0700
From: "bate_G" <Angel.Gerdzhikov@googlemail.com>
Subject: Re: Problems of Perl program with Spreadsheet::ParseExcel module
Message-Id: <1149250880.113743.242920@f6g2000cwb.googlegroups.com>

Hi,
I have the same problem, but with some excel files works, with other
not. The excel format is the same. Any ideas!?

thanks,

bate_G



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

Date: 2 Jun 2006 13:57:10 GMT
From: "Cab" <my_email_address_is_in_my_sig@privacy.net>
Subject: Regexp help.
Message-Id: <xn0en036qa35p4004@news.individual.net>

Hi all.

I'm trying to set up a script to strip out URL's from the body of a
Usenet post.

Any clues please? I have some expressions that I'm using, but they're
very long winded and inefficient, as seen below. At the moment, I've
done this in bash, but want to eventually set up a perl script to do
this.

So far I've got this small script that will remove URLs that start at
the beginning of a line, into a file. This is the easy part (Note, I
know this is messy, but this is still a dev script, at the moment).

---
echo remove spaces from the start of lines
sed 's/^ *//g' sorted_file > 1

echo Remove all '>' from a file.
sed '/>/d' 1 > 2

echo  uniq the file
uniq 2 > 3


echo  Move all lines beginning with http or www into another file
sed -n '/^http/p' 3 > 4
sed -n '/^www/p' 3 >> 4

echo Remove all junk on lines from "space" to EOL
sed '/ .*$/d' 4 > 4.1

echo uniq the file
uniq 4.1 > 4.2

echo So far, I've got a file with all www and http only.
mv 4.2 http_and_www_only
---

Once I've stripped these lines (easy enough), I have a file that
remains like this:

----
And the URL is:
Anton, try reading: url:http://ukrm.net/faq/UKRMsCBT.html
Anyone got any experience with http://www.girlsbike2.com/ ? SWMBO needs
Anyone still got the url of the pages about the woman who keeps going
Are available on: http://www.spete.net/ukrm/sedan06/index.html
are July 6-8. The reason being  "Power Big Meet",
http://www.bigmeet.com/ ,
Are you sure?  http://www.usgpru.net/
a scout around www.nslu2-linux.org - and perhaps there isn't any easier
asked where the sinks were and if you could plug curling tongs into the
----

The result I want is a list like the following:

http://ukrm.net/faq/UKRMsCBT.html
http://www.girlsbike2.com/ 
http://www.spete.net/ukrm/sedan06/index.html
http://www.bigmeet.com/
http://www.usgpru.net/
www.nslu2-linux.org

Can anyone give me some clues or pointers to websites where I can go
into this in more detail please?
-- 
Cab


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

Date: Fri, 02 Jun 2006 16:24:27 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: Regexp help.
Message-Id: <e5phts$jh9$1@mlucom4.urz.uni-halle.de>

Thus spoke Cab (on 2006-06-02 15:57):

> I'm trying to set up a script to strip out URL's from the body of a
> Usenet post.
> The result I want is a list like the following:
> 
> http://ukrm.net/faq/UKRMsCBT.html
> http://www.girlsbike2.com/ 
> http://www.spete.net/ukrm/sedan06/index.html
> http://www.bigmeet.com/
> http://www.usgpru.net/
> www.nslu2-linux.org

The following prints all links
(starting w/http or www) from $text

use:
$> perl dumplinks.pl < text.txt

  #!/usr/bin/perl
  use strict;
  use warnings;

  my $data = do {local $/; <> };
  print "$1\n" while $data =~ /(\b(http|www)\S+)/g;

# or:
#  while (<>) {
#      print "$1\n" while /(\b(http|www)\S+)/g;
#  }


Of course, this can be done by an one-liner ;-)

Regards

Mirco


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

Date: Fri, 02 Jun 2006 07:40:49 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Way to return a file handle from a XSUB?
Message-Id: <m2r727ss3i.fsf@Sherm-Pendleys-Computer.local>

"Dave" <Dave3423@yahoo.com> writes:

> Is there a way to return a filehandle from a XSUB (an XS function) ?

Have you tried simply declaring the function as returning a FILE*? 5.8.x,
at least, has a FILE*->PerlIO typemap, so xsubpp should be able to create
wrapper code to do the right thing.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

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


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