Reading STDIN seems to be breaking my script

R

Ramon F Herrera

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");
 
R

Ramon F Herrera

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");

[...]
 
A

anno4000

Ramon F Herrera said:
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
 
R

Ramon F Herrera

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
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
 
P

Peter J. Holzer

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
 
A

anno4000

[snip, mostly code]
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
 
J

Joe Smith

Ramon said:
On Mar 17, 1:00 pm, (e-mail address removed)-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 <[email protected]> for inclusion. Also note that
at least some of these can be caught with the "use warnings" pragma or
the -w switch.
 
R

Ramon F Herrera

'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
 
M

Martijn Lievaart

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 =-
 
J

Joe Smith

Ramon said:
I began learning Perl around 1993. The llama book did not mention the
'my' feature.

Are you talking about the pink llama book? It's really out of date and
has been replaced by the blue llama book.
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top