Click here to get back home

Threading - share

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Threading - share mumebuhi 08-27-2006
Posted by mumebuhi on August 27, 2006, 3:15 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by xhoster on August 28, 2006, 1:26 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by mumebuhi on August 30, 2006, 5:20 pm
Please log in for more thread options
> > I am trying to understand the differences among these constructs:
> >
> > # 1
> > my $p : shared;
> > $p-> = "My Name";
> >
> > # 2
> > my $p : shared = &share({});
> > $p-> = "My Name";
> >
> > Do 1 and 2 achieve the same thing?
>
> No. 1 gives a "Invalid value for shared scalar" error in nontrivial
> contexts. 2 doesn't (but overriding prototypes is probably bad form,
> anyway).
>
> # 2.5
> my $p = share(%});
> $p-> = "My Name";
>
> # 2.75
> my $p={}; share %$p;
> $p-> = "My Name";
>
> >
> > # 3
> > my %p : shared;
> > $p = "My Name";
> >
> > Is it fair to say that 3 is the simpler form compared to 1 and 2?
>
> In the sense that it is simpler to not use gratuitous references than it is
> to use gratuitous references, sure, 3 is simpler. But using the same
> logic, we could say it is even simpler not to share the variables at all,
> as you don't make meaningful use of the shared nature. Whether you need
> the complexity of sharing, or need the complexity of references, depends on
> the parts of your code you haven't shown us.

I tend to use #3 for a regular usage. However, when I need to construct
a new object, that will be shared by several threads, I have to use #2
in the constructor. Is this reasonable?


Posted by xhoster on August 30, 2006, 5:41 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Similar ThreadsPosted
Multi-Threading May 25, 2005, 2:57 am
Re: Allowing threading with CGI August 27, 2006, 10:36 pm
Re: Allowing threading with CGI August 28, 2006, 12:08 pm
Allowing threading with CGI August 27, 2006, 9:38 pm
Sockets, gui, threading questions December 1, 2004, 10:34 pm
Threading and production environments February 3, 2006, 2:05 pm
Noob threading question July 25, 2006, 9:34 am
perl_parse and multi threading August 1, 2006, 9:09 am
Threading NOT working as expected February 25, 2008, 11:36 am
Assistance with threading ...thread not returning April 12, 2005, 2:48 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap