Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

warn ?!
Hi,
In my program , $sth->execute fails since oracle tables already =
present. It is very natural. But the waring message output line 37 is =
different(just behaves as print) from same kind of message at line 57. =
Any suggestions please..
regards,
Jay=20

regression Testing table( default : reg_test_cols) name :=20
Not able to create reg_test_cols                <?????? ***** this =
output is not similar as line 57 *** >
discrepancy report table ( default : disc_table) name :=20
Not able to create disc_table
at /tmp/selfextract.XXXXXX/install line 57, <> chunk 5.   =20

26  $query=3Dqq { create table reg_test_cols
27                  ( tabname varchar2(40),
28                    colname varchar2(40),
29                    iskey   varchar2(1),
30                    tocomp  varchar2(1),
31                    primary key (tabname,colname) )
32            };
33
34  $sth=3D$dbh->prepare($query)|| warn " $DBI::errstr \n";
35  unless ($sth->execute() )
36           {
37           warn " Not able to create reg_test_cols \n" ;
38           }
39  else
40          {
41          print " Successfully created table reg_test_cols \n";
42          }
43=20
44 =20
45 =20
46  $query=3Dqq { create table disc_table
47                  ( tabname   varchar2(40),
48                    querycols varchar2(2000),
49                    cond      varchar2(2000),
50                    rerun     varchar2(1),
51                    seq       number(4),
52                    primary key (tabname,cond,seq) )
53            };
54  $sth=3D$dbh->prepare($query) || warn " $DBI::errstr\n ";
55  unless ($sth->execute() )
56           {
57           warn " Not able to create disc_table\n " ;
58           }

Report this thread to moderator Post Follow-up to this message
Old Post
Jayakumar Rajagopal
03-27-04 04:15 AM


Re: warn ?!
Hi Jai,

A similar question was posted just yesterday. The
difference between  between the two lines (37 and 57)
is that the second line contains a space after "\n".
As pointed earlier, you can take take it as a
debugging option (ie remove \n or add a space and perl
prints out the line no. too)

:-)
Alok Bhatt

--- Jayakumar Rajagopal <JRajagopal@eagleinvsys.com>
wrote:
> Hi,
>      In my program , $sth->execute fails since
> oracle tables already present. It is very natural.
> But the waring message output line 37 is
> different(just behaves as print) from same kind of
> message at line 57. Any suggestions please..
> regards,
> Jay
>
> regression Testing table( default : reg_test_cols)
> name :
>  Not able to create reg_test_cols
> <?????? ***** this output is not similar as line 57
> *** >
>  discrepancy report table ( default : disc_table)
> name :
>  Not able to create disc_table
>   at /tmp/selfextract.XXXXXX/install line 57, <>
> chunk 5.
>
>     26  $query=qq { create table reg_test_cols
>     27                  ( tabname varchar2(40),
>     28                    colname varchar2(40),
>     29                    iskey   varchar2(1),
>     30                    tocomp  varchar2(1),
>     31                    primary key
> (tabname,colname) )
>     32            };
>     33
>     34  $sth=$dbh->prepare($query)|| warn "
> $DBI::errstr \n";
>     35  unless ($sth->execute() )
>     36           {
>     37           warn " Not able to create
> reg_test_cols \n" ;
>     38           }
>     39  else
>     40          {
>     41          print " Successfully created table
> reg_test_cols \n";
>     42          }
>     43
>     44
>     45
>     46  $query=qq { create table disc_table
>     47                  ( tabname   varchar2(40),
>     48                    querycols varchar2(2000),
>     49                    cond      varchar2(2000),
>     50                    rerun     varchar2(1),
>     51                    seq       number(4),
>     52                    primary key
> (tabname,cond,seq) )
>     53            };
>     54  $sth=$dbh->prepare($query) || warn "
> $DBI::errstr\n ";
>     55  unless ($sth->execute() )
>     56           {
>     57           warn " Not able to create
> disc_table\n " ;
>     58           }
>
> --
> To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-help@perl.org
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>
>


__________________________________
Do you Yahoo!?
Yahoo! Finance Tax Center - File online. File on time.
http://taxes.yahoo.com/filing.html

Report this thread to moderator Post Follow-up to this message
Old Post
Alok Bhatt
03-27-04 04:15 AM


Re: warn ?!
Alok Bhatt wrote:

>
> Hi Jai,

Hi Alok,

Please don't top-post.  Instead, follow the material you are responding to, 
and
trim extraneous matter.

> .... 
> ...
 
>
>  A similar question was posted just yesterday. The
> difference between  between the two lines (37 and 57)
> is that the second line contains a space after "\n".
>  As pointed earlier, you can take take it as a
> debugging option (ie remove \n or add a space and perl
> prints out the line no. too)
>
> :-)
> Alok Bhatt

Not exactly.  It is not the newline "\n" that would give the full output of 
the
warn function, but the $! variable, which contains the most recent warning o
r
error message.  It is pretty much the same as with die().  The problem was n
ot
space after the newline, but the presence of the newline.  The $! variable
should not be followed by anything.  If left as the last element of the warn
 or
die message, it will be unrolled to the line number in the program as well a
s
the line number in the currently selected filehandle.

warn "Something went wrong in function_name(), while doing something dangero
us:
$!";

Greetings! E:\d_drive\perlstuff>perl -w
open IN, 'some_nonexistent_filename' or warn "Something went wrong in main()
, "
. "while doing something dangerous:\n $!";
my $stuff = <IN>;
print $stuff;

^Z
Something went wrong in main(), while doing something dangerous:
No such file or directory at - line 1.
readline() on closed filehandle IN at - line 3.
Use of uninitialized value in print at - line 4.


Joseph


Report this thread to moderator Post Follow-up to this message
Old Post
R. Joseph Newton
03-28-04 04:53 AM


Re: warn ?!
On Mar 27, 2004, at 12:10 AM, R. Joseph Newton wrote:

> Not exactly.  It is not the newline "\n" that would give the full
> output of the
> warn function, but the $! variable, which contains the most recent
> warning or
> error message.

I believe you are confusing two often paired, but not otherwise related
features of Perl.

warn() is a tool for delivering non-fatal error messages.  It behaves
differently depending if the provided message does or doesn't end in a
newline character, as has been discussed in this thread.

$! is a Perl interface to C's "errno" variable.  It is set by failed
system/library calls.

While it may often be useful to issue a warn()ing including $!, it is
by no means required.  It may be useful to issue warn()ings including
many variables.  $@ is a common example, in fact, it's the default
message warn() will display if not provided one.  You may want to use
your own variables, so simply print a message in your own words about
what happened.  That's what warn() is for.

James


Report this thread to moderator Post Follow-up to this message
Old Post
James Edward Gray II
03-28-04 04:53 AM


Re: warn ?!
James Edward Gray II wrote:

> On Mar 27, 2004, at 12:10 AM, R. Joseph Newton wrote:
> 
>
> I believe you are confusing two often paired, but not otherwise related
> features of Perl.

Actually, I was starting to think that I had misstated the above, by saying
"output of the warn function, but I think I was closer to the mark.  You can
print $! and get the error message, but the line information is the product 
of
warn or die:

open IN, 'some_nonexistent_filename' or print $!;
^Z
Name "main::IN" used only once: possible typo at - line 1. # built-in compil
er
warning
No such file or directory # simply printing $!

open IN, 'some_nonexistent_filename' or warn $!;
^Z
..
No such file or directory at - line 1.

>
> warn() is a tool for delivering non-fatal error messages.  It behaves
> differently depending if the provided message does or doesn't end in a
> newline character, as has been discussed in this thread.
>
> $! is a Perl interface to C's "errno" variable.  It is set by failed
> system/library calls.
>
> While it may often be useful to issue a warn()ing including $!, it is
> by no means required.

In this case, James, it is what the OP was looking for.  He specifically saw
 a
problem with having the warning message come out as a simple print statement
.
I'm not terribly concerned about the internal mplementation.  I am speaking 
of
the effect.  Unless I am missing something about what the OP wnated here.

> It may be useful to issue warn()ings including
> many variables.  $@ is a common example, in fact, it's the default
> message warn() will display if not provided one.  You may want to use
> your own variables, so simply print a message in your own words about
> what happened.  That's what warn() is for.

I agree, which is why I tend to recommend the darn-near canonical form I
showed.  Interestingly enough, it is almost the same generalized warning
produced by $@:
Greetings! E:\d_drive\perlStuff\hdr>perl -w
open IN, 'some_nonexistent_filename' or warn $@;
^Z
Name "main::IN" used only once: possible typo at - line 1.
Warning: something's wrong at - line 1.
except that the $@ adds the Warning: prefix.

It seems pretty clear to me, that although modular in their function, these 
Perl
built-in variables were precisely designed to work with the warn and die
functions.  I'll hold with my essential point--that you get a lot more usefu
l
information out of your warning by havng the $! at the end of your custom
message.  I would recommend always using such custom messages also, and putt
ing
design thought into them.  That is why I suggested having them include the n
ame
of the function containing them, and why I generally specify the operation b
eing
attempted.

Joseph



Report this thread to moderator Post Follow-up to this message
Old Post
R. Joseph Newton
03-28-04 04:53 AM


Re: warn ?!
On Mar 27, 2004, at 1:32 PM, R. Joseph Newton wrote:

> It seems pretty clear to me, that although modular in their function,
> these Perl
> built-in variables were precisely designed to work with the warn and
> die
> functions.  I'll hold with my essential point--that you get a lot more
> useful
> information out of your warning by havng the $! at the end of your
> custom
> message.

You still sound pretty  to me.  ;)

Fact:  If the warn() message ends is a newline character, the line
number is not appended.

Fact:  This has nothing to do with ANY variables, it is the way warn()
is designed.

Fact:  This is the original question of this thread and what most of
the replies address.  You might like to reread them at this point.

Please run these two one liners, observing the differences in output,
for a good example of this:

perl -e 'warn "Test Warning"'

perl -e 'warn "Test Warning\n"'

Hope that clears things up.

James


Report this thread to moderator Post Follow-up to this message
Old Post
James Edward Gray II
03-28-04 04:53 AM


Re: warn ?!
James Edward Gray II wrote:

> Fact:  This has nothing to do with ANY variables, it is the way warn()
> is designed.

Trivia:

Did you know that $! does NOT contain an error string. It contains the
error *number*. The only reason you see a error sting is that it has an
overloaded stringification operator that calls strerror() on the numeric
value that it contains.

# assuming the file 'foo' does not exist in current directory.

perl -e 'open FOO,"foo" or print $!+0'
=> 2

perl -MPOSIX -e 'open FOO,"foo";print strerror $!+0'
=> No such file or directory

Randy.


Report this thread to moderator Post Follow-up to this message
Old Post
Randy W. Sims
03-28-04 04:53 AM


Re: warn ?!
James Edward Gray II wrote:

> On Mar 27, 2004, at 1:32 PM, R. Joseph Newton wrote:
> 
>
> You still sound pretty  to me.  ;)

> Fact:  If the warn() message ends is a newline character, the line
> number is not appended.
>
> Fact:  This has nothing to do with ANY variables, it is the way warn()
> is designed.

I see.  It does seem a bit quirky, though, to use whitespace in this way.  I
wasn't really aware of this oddity in the design of warn().  I guess it make
s
sense, somehow.  It makes more sense, though, to just provide some context
iformation, then get the more specific error or warning message ctained in t
he
variable.  Whatever the particular features that come and go with the choice
 of
whitespace, it makes more sense to explicitly call for the information provi
ded
in $!.

>
>
> Fact:  This is the original question of this thread and what most of
> the replies address.  You might like to reread them at this point.
>
> Please run these two one liners, observing the differences in output,
> for a good example of this:

Sorry, they are non-portable:
reetings! E:\d_drive\perlStuff>perl -e 'warn "Test Warning"'
an't find string terminator "'" anywhere before EOF at -e line 1.

>
>
> perl -e 'warn "Test Warning"'
>
> perl -e 'warn "Test Warning\n"'
>
> Hope that clears things up.
>
> James

Got it.  Nice point.  Now back to business.  You get a lot more information 
back
by asking for information.

Joseph


Report this thread to moderator Post Follow-up to this message
Old Post
R. Joseph Newton
03-28-04 04:53 AM


Re: warn ?!
"Randy W. Sims" wrote:

> James Edward Gray II wrote:
> 
>
> Trivia:
>
> Did you know that $! does NOT contain an error string. It contains the
> error *number*. The only reason you see a error sting is that it has an
> overloaded stringification operator that calls strerror() on the numeric
> value that it contains.
>
> # assuming the file 'foo' does not exist in current directory.
>
> perl -e 'open FOO,"foo" or print $!+0'
> => 2
>
> perl -MPOSIX -e 'open FOO,"foo";print strerror $!+0'
> => No such file or directory
>
> Randy.

Cool.  Somehow, though It seems {6 * 1 == 12 / 2}-ish.  By the time the
 variable
is effectively accessed, the text is there.

Greetings! E:\d_drive\perlStuff>perl
open IN, 'some_nonexistent_filename' or print $!;
^Z
No such file or directory

What is intriguing to me in this is that an overloaded operator wouuld be
attched to a variable.  this sounds like it gets into prtions of Perl that I
've
never really delved into.  Is $! actually sored as a number?

Joseph


Report this thread to moderator Post Follow-up to this message
Old Post
R. Joseph Newton
03-28-04 04:53 AM


Re: warn ?!
"Randy W. Sims" wrote:
>
> James Edward Gray II wrote:
> 
>
> Trivia:
>
> Did you know that $! does NOT contain an error string. It contains the
> error *number*. The only reason you see a error sting is that it has an
> overloaded stringification operator that calls strerror() on the numeric
> value that it contains.

Did you know that $! is one of those "magical" variables that contains
both a number and a string at the same time!  AMAZING BUT TRUE!  Here is
an exerpt from the perl source:

case '!':
#ifdef VMS
sv_setnv(sv, (NV)((errno == EVMSERR) ? vaxc$errno : errno));
sv_setpv(sv, errno ? Strerror(errno) : "");
#else
{
int saveerrno = errno;
sv_setnv(sv, (NV)errno);
#ifdef OS2
if (errno == errno_isOS2 || errno == errno_isOS2_set)
sv_setpv(sv, os2error(Perl_rc));
else
#endif
sv_setpv(sv, errno ? Strerror(errno) : "");
errno = saveerrno;
}
#endif
SvNOK_on(sv);   /* what a wonderful hack! */
break;


Where you can see that sv_setpv() sets the string part of $! and
sv_setnv() sets the numeric part.


John
--
use Perl;
program
fulfillment

Report this thread to moderator Post Follow-up to this message
Old Post
John W. Krahn
03-28-04 04:53 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:58 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.