Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Reading STDIN seems to be breaking my script

Reply
Thread Tools

Reading STDIN seems to be breaking my script

 
 
Ramon F Herrera
Guest
Posts: n/a
 
      03-17-2007

Anyone familiar with the Asterisk open source PBX out there? Read
on...

An AGI (Asterisk Gateway Interface) Perl script is very similar to a
CGI Perl script. My problem is introduced by the code commented out
below. As soon as the code is executed, the rest of the script doesn't
work anymore because the prompt is either not payed or (most likely)
it is played nut I cannot hear it.

-Ramon

---------------------
#!/bin/perl -w

use Asterisk::AGI;


$|=1;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
sleep(1);

# while(<STDIN>) {
# chomp;
# last unless length($_);
# if (/^agi_(\w+)\:\s+(.*)$/) {
# $AGI{$1} = $2;
# }
# }
#
# $CallerID = $AGI{"agi_callerid"};
# $CallerIdName = $AGI{"agi_calleridname"};

$Welcome = "faxback/Welcome";
$enterFaxNumber = "faxback/EnterFaxNumber";
$Farewell = "faxback/Farewell";

$AGI->stream_file("$Welcome", "*");

$FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");

 
Reply With Quote
 
 
 
 
Ramon F Herrera
Guest
Posts: n/a
 
      03-17-2007

Anyone familiar with the Asterisk open source PBX out there? Read
on...

An AGI (Asterisk Gateway Interface) Perl script is very similar to a
CGI Perl script. My problem is introduced by the code commented out
below. As soon as the code is executed, the rest of the script doesn't
work anymore because the prompt is either not played or (most likely)
it is played but I cannot hear it.

-Ramon

---------------------
#!/bin/perl -w

use Asterisk::AGI;

$|=1;
my $AGI = new Asterisk::AGI;
my %input = $AGI->ReadParse();
sleep(1);

# while(<STDIN>) {
# chomp;
# last unless length($_);
# if (/^agi_(\w+)\:\s+(.*)$/) {
# $AGI{$1} = $2;
# }
# }
#
# $CallerID = $AGI{"agi_callerid"};
# $CallerIdName = $AGI{"agi_calleridname"};

$Welcome = "faxback/Welcome";
$enterFaxNumber = "faxback/EnterFaxNumber";
$Farewell = "faxback/Farewell";

$AGI->stream_file("$Welcome", "*");

$FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");

[...]


 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      03-17-2007
Ramon F Herrera <> wrote in comp.lang.perl.misc:
>
> Anyone familiar with the Asterisk open source PBX out there? Read
> on...
>
> An AGI (Asterisk Gateway Interface) Perl script is very similar to a
> CGI Perl script. My problem is introduced by the code commented out
> below. As soon as the code is executed, the rest of the script doesn't
> work anymore because the prompt is either not played or (most likely)
> it is played but I cannot hear it.
> -Ramon
>
> ---------------------
> #!/bin/perl -w
>
> use Asterisk::AGI;
>
> $|=1;
> my $AGI = new Asterisk::AGI;
> my %input = $AGI->ReadParse();
> sleep(1);
>
> # while(<STDIN>) {
> # chomp;
> # last unless length($_);
> # if (/^agi_(\w+)\:\s+(.*)$/) {
> # $AGI{$1} = $2;


This line accesses the hash %main::AGI. It seems unlikely that
you want to do this. It wouldn't run under strict.

> # }
> # }
> #
> # $CallerID = $AGI{"agi_callerid"};
> # $CallerIdName = $AGI{"agi_calleridname"};
>
> $Welcome = "faxback/Welcome";
> $enterFaxNumber = "faxback/EnterFaxNumber";
> $Farewell = "faxback/Farewell";
>
> $AGI->stream_file("$Welcome", "*");
>
> $FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");
>
> [...]


The commented-out code would very probably not work as intended
anyhow. Make sure it does what you want it to do. As a first
step, add "use strict;" near the beginning of the script.

Anno
 
Reply With Quote
 
Ramon F Herrera
Guest
Posts: n/a
 
      03-17-2007
On Mar 17, 1:00 pm, anno4...@radom.zrz.tu-berlin.de wrote:
> Ramon F Herrera <r...@conexus.net> wrote in comp.lang.perl.misc:
>
>
>
>
>
> > Anyone familiar with the Asterisk open source PBX out there? Read
> > on...

>
> > An AGI (Asterisk Gateway Interface) Perl script is very similar to a
> > CGI Perl script. My problem is introduced by the code commented out
> > below. As soon as the code is executed, the rest of the script doesn't
> > work anymore because the prompt is either not played or (most likely)
> > it is played but I cannot hear it.
> > -Ramon

>
> > ---------------------
> > #!/bin/perl -w

>
> > use Asterisk::AGI;

>
> > $|=1;
> > my $AGI = new Asterisk::AGI;
> > my %input = $AGI->ReadParse();
> > sleep(1);

>
> > # while(<STDIN>) {
> > # chomp;
> > # last unless length($_);
> > # if (/^agi_(\w+)\:\s+(.*)$/) {
> > # $AGI{$1} = $2;

>
> This line accesses the hash %main::AGI. It seems unlikely that
> you want to do this. It wouldn't run under strict.
>
> > # }
> > # }
> > #
> > # $CallerID = $AGI{"agi_callerid"};
> > # $CallerIdName = $AGI{"agi_calleridname"};

>
> > $Welcome = "faxback/Welcome";
> > $enterFaxNumber = "faxback/EnterFaxNumber";
> > $Farewell = "faxback/Farewell";

>
> > $AGI->stream_file("$Welcome", "*");

>
> > $FaxNumber = $AGI->get_data($enterFaxNumber, "10000", "11");

>
> > [...]

>
> The commented-out code would very probably not work as intended
> anyhow. Make sure it does what you want it to do. As a first
> step, add "use strict;" near the beginning of the script.
>
> Anno



Thanks for your help, Anno. I took the commented out code from an AGI
program called agi-test.agi which works and comes with the Asterisk
distribution. However, I did neglect to place the "use strict" line,
and after I added it I am getting all kinds of errors like this one:

Global symbol "$Welcome" requires explicit package name at
faxback.agi line 24.

I guess my problem is that when I learned Perl, there was no such
thing as "my". What the heck is that? I have a vague recollection that
it was added to make the language object oriented? Where can I read
about that stuff? Is there a guide about this "my" new deal for
programmers who already know the "old" Perl?

TIA,

-Ramon


 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      03-17-2007
On 2007-03-17 18:14, Ramon F Herrera <> wrote:
> I guess my problem is that when I learned Perl, there was no such
> thing as "my".


Must have been a long time ago. if I remember correctly, "my" was
introduced with perl 5.0 in 1994.

> What the heck is that? I have a vague recollection that
> it was added to make the language object oriented?


No, it just declares a lexically scoped local variable, as most other
programming languages have them (unlike "local" which creates a
dynamically scoped local variable).

> Where can I read about that stuff? Is there a guide about this "my"
> new deal for programmers who already know the "old" Perl?


perldoc is your friend.

perldoc -f my

gives you a short description and also says 'See "Private Variables via
my()" in perlsub for details'. So

perldoc perlsub

is what you should read. If you ares still used to perl4, you should
probably read all of the other core docs as well.

hp


--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      03-17-2007
Ramon F Herrera <> wrote in comp.lang.perl.misc:
> On Mar 17, 1:00 pm, anno4...@radom.zrz.tu-berlin.de wrote:
> > Ramon F Herrera <r...@conexus.net> wrote in comp.lang.perl.misc:
> >
> >
> >
> >
> >
> > > Anyone familiar with the Asterisk open source PBX out there? Read
> > > on...


[snip, mostly code]

> > The commented-out code would very probably not work as intended
> > anyhow. Make sure it does what you want it to do. As a first
> > step, add "use strict;" near the beginning of the script.
> >
> > Anno

>
>
> Thanks for your help, Anno. I took the commented out code from an AGI
> program called agi-test.agi which works and comes with the Asterisk
> distribution. However, I did neglect to place the "use strict" line,
> and after I added it I am getting all kinds of errors like this one:
>
> Global symbol "$Welcome" requires explicit package name at
> faxback.agi line 24.
>
> I guess my problem is that when I learned Perl, there was no such
> thing as "my". What the heck is that? I have a vague recollection that
> it was added to make the language object oriented? Where can I read
> about that stuff? Is there a guide about this "my" new deal for
> programmers who already know the "old" Perl?


Well, the new deal is Perl 5 and happened twelve years ago.

If you are going to pick up Perl (again), you should definitely learn
about "my()" (lexical variables, nothing to do with OO) and more things
that were added with Perl 5. "perldoc -f my" is the documentation of
"my()", but there's much more.

If the code you're dealing with is not strict-safe, I'd eye it with
suspicion.

If it *is* strict-safe, and you have taken a snippet of (modern) Perl
and are trying to make it run under Perl 4 style code you wrote, forget
it. Start with the whole thing and modify it to do what you want it
to do, sticking to the style you find, learning about (looking up) new
features as you go along.

Anno
 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      03-17-2007
Ramon F Herrera wrote:
> On Mar 17, 1:00 pm, anno4...@radom.zrz.tu-berlin.de wrote:
>
> I guess my problem is that when I learned Perl, there was no such
> thing as "my". What the heck is that? I have a vague recollection that
> it was added to make the language object oriented? Where can I read
> about that stuff?


For starters, use the command "perldoc perl" (or "man perl").
It has a list of topics that make up Perl's core documentation set.

In particular, you should look at this section in "perldoc perltrap":

Perl4 to Perl5 Traps

Practicing Perl4 Programmers should take note of the following
Perl4-to-Perl5 specific traps.

They're crudely ordered according to the following list:

Discontinuance, Deprecation, and BugFix traps
Anything that's been fixed as a perl4 bug, removed as a perl4 fea-
ture or deprecated as a perl4 feature with the intent to encourage
usage of some other perl5 feature.

Parsing Traps
Traps that appear to stem from the new parser.

Numerical Traps
Traps having to do with numerical or mathematical operators.

General data type traps
Traps involving perl standard data types.

Context Traps - scalar, list contexts
Traps related to context within lists, scalar statements/declara-
tions.

Precedence Traps
Traps related to the precedence of parsing, evaluation, and execu-
tion of code.

General Regular Expression Traps using s///, etc.
Traps related to the use of pattern matching.

Subroutine, Signal, Sorting Traps
Traps related to the use of signals and signal handlers, general
subroutines, and sorting, along with sorting subroutines.

OS Traps
OS-specific traps.

DBM Traps
Traps specific to the use of "dbmopen()", and specific dbm imple-
mentations.

Unclassified Traps
Everything else.

If you find an example of a conversion trap that is not listed here,
please submit it to <> for inclusion. Also note that
at least some of these can be caught with the "use warnings" pragma or
the -w switch.
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      03-18-2007
Ramon F Herrera <> wrote:

> I guess my problem is that when I learned Perl, there was no such
> thing as "my".


> Where can I read
> about that stuff?



"Coping with Scoping":

http://perl.plover.com/FAQs/Namespaces.html


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Ramon F Herrera
Guest
Posts: n/a
 
      03-18-2007
On Mar 17, 6:23 pm, Abigail <abig...@abigail.be> wrote:
>
> 'my' was introduced in Perl 5.000, which dates from 1994. The same
> version introduced 'strict.pm', a module that you must use to get the
> 'Global symbol "$Welcome" requires explicit package name' error message.



Abigail:

I began learning Perl around 1993. The llama book did not mention the
'my' feature. I have been writing my-less scripts, and I didn't need
it until now. Perl is not my primary programming language, which are C
and Java. But I be using Perl much more often now, since I chose it
(among a wide array of choices) for my AGI and other scripts.


>
> I'm a bit baffled that you claim to be ignorant of Perl5 features, yet
> you do use them.
>


I just lifted some code (from a demo AGI script) which I am trying to
integrate into my code.

-Ramon



 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      03-18-2007
On Sun, 18 Mar 2007 13:06:21 -0700, Ramon F Herrera wrote:

> I began learning Perl around 1993. The llama book did not mention the
> 'my' feature. I have been writing my-less scripts, and I didn't need it
> until now. Perl is not my primary programming language, which are C and
> Java. But I be using Perl much more often now, since I chose it (among
> a wide array of choices) for my AGI and other scripts.


Well, get a modern Perl book! Perl changed and is now my language of
choice for almost anything. It's not perfect, not by a long way, but it
gets the job done. Investing in learning modern Perl is a wise choice.

M4
-= Who hasn't written a single line of C or C++ in the past 2
years =-
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 1 Week Ago 04:30 PM
How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute() Ben C Programming 2 08-29-2009 09:47 PM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Looking for a breaking news rss feed that really contains breaking news Amy XML 0 02-22-2005 06:31 PM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57