Click here to get back home

use one subroutine's variable value in another subroutine inside a module.

 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
use one subroutine's variable value in another subroutine inside a module. king 04-26-2007
Get Chitika Premium
Posted by king on April 26, 2007, 9:28 am
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 Mumia W. on April 26, 2007, 11:32 am
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 Glenn Jackman on April 26, 2007, 12:51 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 Brian McCauley on April 26, 2007, 1:08 pm
Please log in for more thread options
> I have a module named TPWizardMgr.pm as below.

> sub load_school_template
> {
> my $self = shift;
#...
> my @template_subject_period;
# Put lots of stuff in @template_subject_period;

> }
>
> sub get_course_info
> {
my $self = shift;
# Stuff that needs @template_subject_period calculated above
> }
>
> 1;
> ==================================================================
>
> But I want to use the variable @template_subject_period in the
> subroutine get_course_info( ).
>
> I am not able to use this @template_subject_period variable value in
> the get_course_info subroutine.

No because it's lexically scoped to the other subroutine.

If you want data that persists from one method call to another you
store it _in_the_object_.



> How I can do this.


sub load_school_template
{
my $self = shift;
#...
# Put lots of stuff in @};
}

sub get_course_info
{
my $self = shift;
# Stuff that uses @};
}


Now I've answered the question you asked I'll compose another follow-
up that addresses some other issues with your code.


Posted by injunjoel on April 26, 2007, 1:35 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
Using one methods variable value in another method inside a module April 29, 2007, 9:04 am
Using $SIG assignment inside a subroutine ... November 7, 2004, 2:38 pm
Use of constant inside a module? April 25, 2007, 10:09 am
ISO good inside-out objects module December 24, 2005, 1:37 pm
Help with variable with regex inside. December 4, 2006, 2:05 am
subroutine's name February 4, 2008, 4:34 pm
Variable containing name of function inside a package June 27, 2005, 5:10 pm
How do i get the charactors inside the ( ) from a string variable March 25, 2006, 2:46 pm
subroutine's returned value December 2, 2005, 11:58 am
using the first variable on the command line inside a perl program October 13, 2006, 4:52 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap