Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 30th, 2001, 02:31 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
modify $!

Ok, I've done a bit of experementation, with no sucess... Is there a way to set $! to a string to send an error back?

I'm writing a small library so to speak... and I want people to be able to use things like this


$var = mysub($othervar) || die($!)

Is it possible at all?

Reply With Quote
  #2  
Old July 30th, 2001, 03:07 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
perlvar says:

If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.) If used in a string context, yields the corresponding system error string. You can assign to $! to set errno if, for instance, you want "$!" to return the string for error n, or you want to set the exit value for the die() operator.
__________________
- dsb -
Perl Guy

Reply With Quote
  #3  
Old July 30th, 2001, 03:56 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I had found that...

I had already read that... but I couldn't make any sense of it... and I still can't...

Reply With Quote
  #4  
Old July 30th, 2001, 06:51 PM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
I don't really get what you're asking. Why not just do this?

Code:
my $var = mysub($othervar) or die('Couldn\'t get var: '.$!);


I use this everywhere and it works beautifully for me.

Reply With Quote
  #5  
Old July 30th, 2001, 07:17 PM
Flame Flame is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 25 Flame User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok

Ok... mabey an example of what I tried will make it obvious...


sub mysub {
if(!shift){
my ($package, $file, $line) = caller;
$! = "Error on line $line of $package in $file: Failed to pass true value";
return;
}else{
return "That was true!";
}
}

sub dienice {

print shift;
exit;

}

Now, of course thats a worthless sub, but I want to be able to SET $! like that...

so that if someone did this:

$myvar = mysub(0) || dienice($!);

It would spit out something resembling this:

Error on line 4 of somepackage in myfile.pl: Failed to pass true value


Note: All code there was thrown together and probably would NOT execute properly...

I hope that helped explain my goal...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > modify $!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway