Feature request: new $__ variable or a new operator: &&$

Hello!

  I want to make do a nested hash structure, which seems like that:

  my  $pname   =  $self->{db}->{product}->offers->{   $product_id}  ->
{name};

This kind of structures can be easily created by TableMap.

Problem: If any  of the hash keys are undef, then  perl "die"-ing with
an error: Cannot use undef as a HASH reference...

I suggest  two kind of solution  in the new (perl6)  language, because
I think perl5 don't have good solution for that:

1, $__ variable, which is the result of the last operation, e.g:

my $pname  = $self->{db}  && $__->{product}  && $__->offers  && $__->{
$product_id } && $__->{name}

2, &&$ operator, which can be used like that:

my  $pname  =  $self->{db  &&$  ->{product}  &&$  ->offers  &&$  ->  {
$product_id } &&$ ->{name};

I  suggest the  second, because  it is  more straightforward,  but the
first is more flexible.

Regards,

dLux
--
Linux is like wigwam: no windows, no gates, apache inside!
0
dlux
8/2/2000 8:33:36 AM
perl.perl6.language 6830 articles. 0 followers. Follow

2 Replies
622 Views

Similar Articles

[PageSpeed] 13

dLux <dlux@kapu.hu> writes:

> Hello!
> 
>   I want to make do a nested hash structure, which seems like that:
> 
>   my  $pname   =  $self->{db}->{product}->offers->{   $product_id}  ->
> {name};
> 
> This kind of structures can be easily created by TableMap.
> 
> Problem: If any  of the hash keys are undef, then  perl "die"-ing with
> an error: Cannot use undef as a HASH reference...
> 
> I suggest  two kind of solution  in the new (perl6)  language, because
> I think perl5 don't have good solution for that:
> 
> 1, $__ variable, which is the result of the last operation, e.g:
> 
> my $pname  = $self->{db}  && $__->{product}  && $__->offers  && $__->{
> $product_id } && $__->{name}
> 
> 2, &&$ operator, which can be used like that:
> 
> my  $pname  =  $self->{db  &&$  ->{product}  &&$  ->offers  &&$  ->  {
> $product_id } &&$ ->{name};
> 
> I  suggest the  second, because  it is  more straightforward,  but the
> first is more flexible.

reduce {last unless defined $a; eval "\$a->$b"} $self,
        qw/{db} {product} offers {$product_id} {name}/;

Hmm... that is a tad unwieldy. And we don't have reduce yet. And I'm
not entirely sure that last would work how you want it to...

-- 
Piers

0
pdcawley
8/2/2000 11:20:14 AM
/--- On Wed, Aug 02, 2000 at 12:20:14PM +0100, Piers Cawley wrote:
| > 1, $__ variable, which is the result of the last operation, e.g:

| > my  $pname  =  $self->{db}  && $__->{product}  &&  $__->offers  &&
| > $__->{
| > $product_id } && $__->{name}

| > 2, &&$ operator, which can be used like that:

| > my $pname = $self->{db &&$ ->{product} &&$ ->offers &&$ -> {
| > $product_id } &&$ ->{name};

| > I  suggest the  second, because  it is  more straightforward,  but
| > the
| > first is more flexible.
|
| reduce {last unless defined $a; eval "\$a->$b"} $self,
|         qw/{db} {product} offers {$product_id} {name}/;
|
| Hmm... that  is a tad  unwieldy. And we  don't have reduce  yet. And
| I'm
| not entirely sure that last would work how you want it to...
\---

Where I  can find  the "reduce"  command? I  understand how  it works,
but this is *VERY* dirty.

The $pname=eval{ ... } block is much cleaner...

But what about the suggestion? Is it a good suggestion?

How will I make it formal?

dLux
--
perl                             -e                             'print
$i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
0
dlux
8/2/2000 2:41:12 PM
Reply:

Similar Artilces:

NEW NEW NEW
hi I have a huge form to build on an asp.net page with multiple fields  that come from and also connect to (postback=true) 10 different tables{database is access for now } .which controls would be helpful please suggest. Also how about usign infopath to build forms and hosting it on iis is it feasible..please advice. Thanks in advance Environment: Visual studio 2005 ,iis webserver,ms access,Thanks to all the PROS who are helping other developers.. Hi, For ASP.NET 2.0 Hosting purpose I am currently using GoDaddy.com. And satisfied with the service.RegardsKuldeep Deokule&nbs...

Difference Between The && and the & operators
could somebosy please explain the difference to me between using the && and the & operators. I have read the MSDN documentation but am non the wiser. thanks. Take a look at this blog entry: http://www.johnsample.com/articles/BitwiseEnums.aspx The 8th comment on that page has a great C# example of why/when you'd use the single & for"If you make it idiot proof, they'll build a better idiot"...

new lists: perl6-language-flow, perl6-language-io and perl6-language-unlink
WORKING GROUP: perl6-language-flow CHAIR: uri guttman <uri@sysarch.com> MISSION: Draft, discuss, and revise RFCs relating to flow control in Perl 6, eg switch/case, looping, etc. Suggest/request other flowcontrol-related lists if appropriate DEADLINE: 3 weeks, extensible on request (end 26th August?) DESCRIPTION: Submit flowcontrol-related RFCs to the Perl 6 librarian as they are developed. WORKING GROUP: perl6-language-unlink CHAIR: Nathan Wiger <nate@wiger.org> MISSION: Discuss and re...

new hardware & new errors
I'm running an old version of suse 9.0 I created an image using acronis true image, and loaded the image to a different workstation with different hardware. Now, I knew there would be problems, but I didn't figure it would be such a pain to fix. Everything about the new workstation is different. I'm still running an ide drive though. Here's what I get "waiting for device /dev/sda2 to appear" It shows that screen for about 3 seconds, then spits out all this: tty44 tty45 tty46 tty47 tty48..... on and on and on. Finally it comes to: "No ro...

&& In Generated Javascript Becomes &amp;&amp;
I am trying to write client side scripts in c#, asp.net V 1.4. The && operator is generated in the javascript as &amp;amp;, which causes errors.  How can I avoid this? (Code below)  Thanks in advance.   script = "<script language='javascript' type='text/javascript'>\n"; script += "if (Form1." + tbxA.ClientID + ".value == '' && "; script += "Form1." + tbxB.ClientID + ".value == '') {"; script += "Form1." + cbxC.ClientID + ".Checked = false;}"; ...

"Open", "Open in new window", "Open in new tab" are greyed-out after drag&drop operation
Name: Dmitriy Email: dadotivanovathotmaildotcom Product: Firefox Release Candidate Summary: "Open", "Open in new window", "Open in new tab" are greyed-out after drag&drop operation Comments: Steps to Reproduce: 1. Drag&drop a bookmark from the Bookmarks Menu or Bookmarks Toolbar to the Tab bar. 2. Right-click on any bookmark (from the same folder, if darged from Menu, or from the visible part of Bookmarks Toolbar) Result: "Open", "Open in new window", "Open in new tab" are greyed-out Browser Details: Moz...

superreview requested: [Bug 331670] "Search" CM item needs to respect new & background keys/toggles : [Attachment 242370] updated for new method name
froodian <stridey@gmail.com> has asked Mike Pinkerton <mikepinkerton@mac.com> for superreview: Bug 331670: "Search" CM item needs to respect new & background keys/toggles https://bugzilla.mozilla.org/show_bug.cgi?id=331670 Attachment 242370: updated for new method name https://bugzilla.mozilla.org/attachment.cgi?id=242370&action=edit ------- Additional Comments from froodian <stridey@gmail.com> Looking at this further, adding an alternate the Right Way for the context menu item will be a little bit tricky, since it requires that menu items can ha...

New Feature Request: A Reply
Name: Clendon Gibson Email: bsandyman_at_yahoo.com Product: Thunderbird Summary: New Feature Request: A Reply - New Thread Comments: An e-mail list I am on has trouble where people hijack threads. A lot of them are computer novices and so this is not surprising. It is also not surprising that they use reply because that is the easiest and most straightforward way to send a message to the group. It occurred to me that if an e-mail client had a "Reply - New Thread" that would compose a new message instead of a reply complete with threaded headers, that this p...

Save & Close
Hi All - I have a WebForm with a GridView on it - imbedded in the gridview in one of the columns is a hyperlink. when the link in a row is clicked - I pop a new window where some specialized data entry and updating can be done. Currently - on the popup form there is a "Save" button and a "Close" button. What the optimal resolution would be is to have a "Save and Close" button and a "Save and New" button. The "Save and New" button is easy as it can all be handled server-side (does the save to the database - resets some controls - displays message - etc). It is the "Save and Close" that I ...

Merging 2 GroupWise 5.5 & 6.5 domains & moving to new hardware & tree
--____HUUGUAJLOXECDNBRZZJF____ Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable I have two GroupWise domains, which I wish to merge into one. At the same = time, we are moving one to new hardware and a new tree... here's the = details: Domain #1 is the primary domain. It is GroupWise v6.5sp3, and all = components reside on a NetWare v6.5 box. It only has one post office. The = GroupWise objects reside in eDirectory tree #1. There are about 30 users = here. Domain #2 is a secondary (external) domain. It is GroupWise v5.5 (not sure = ...

superreview requested: [Bug 286926] && should be & in nsMsgDBView::ToggleExpansion : [Attachment 178041] Patch changing '&&' to '&'
Jean-Francois Ducarroz <ducarroz@ducarroz.org> has asked David Bienvenu <bienvenu@nventure.com> for superreview: Bug 286926: && should be & in nsMsgDBView::ToggleExpansion https://bugzilla.mozilla.org/show_bug.cgi?id=286926 Attachment 178041: Patch changing '&&' to '&' https://bugzilla.mozilla.org/attachment.cgi?id=178041&action=edit ...

new-patches & new-tids forum updates?
Kim, you checking to see if anyone is watching? :-) No new updates in either of those forums in a while now... [yawn] huh...what...did someone say my name?...... The feeds for TIDS and Patches have been changed to be product specific and we now have direct links to the feed instead of porting them into a forum. If you go to the product specific forum, that's where you'll find them now. For example OES: http://forums.novell.com/novell/novell-product-discussion-forums/open-enterprise-server/ At the top you'll see a heading "What's New for Open Enterprise ...

New Year time for a new avatar & sig
As has become something of a tradition with me I change both at the start of the New Year. Since using only Opensuse from 10.2 on, thanks to all of you here, I've become a little bit wiser in the ways of Opensuse. Because I feel a little bit & I do stress *little bit!* I chose an owl as an avatar for 2011. The new sig when I saw it I thought, "hey a Linux forum would be an ideal place for that!" Because one if there's one thing I've learned here I've learned there's more than one way to do anything. Not just in Linux but in life as well. -- The...

Replacement of & , &amp;
I was trying this java script inside a mozilla extension but the browser shows me error this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); XML Parsing Error: not well-formed at replace(/&/g,'&amp;') Any thoughts ? Thanks On Fri, 30 May 2008 10:26:19 -0700 (PDT), sb wrote: > I was trying this java script inside a mozilla extension but the > browser shows me error > this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'); > ...

Web resources about - Feature request: new $__ variable or a new operator: &&$ - perl.perl6.language

Resources last updated: 12/12/2015 8:55:14 AM