> BTW, avoid using $a and $b for variable names, > even > in examples. They have a special meaning in the perl > 'sort' function. > >
Good to know. I wasn't really aware. I just used them here to shorten the name of the variable. > : This is all making sense, sort of like when shift > : operates on $_. > > Yes, but 'shift' operates on @_ not $_. That > would > make sense because 'shift' is shifting a list (or > array). Perhaps you are thinking of 'split'. It > operates on $_ by default. > My mistake. I meant something like this: if (my $match =~ /'Shot'/) { my @matchedLines = unshift; ) however, I'd really use push there, but unshift would work as well I believe. I was thinking of shift and how it relates to push. I understand shift is an array function, not a scalar, but, as usual, I've failed to be clear. <snip> > : So when Cozens uses something like: > : sub link($$); > : if he were passing arrays, he'd do: > : sub link(@@); > : and hashes: > : sub link(%%); > : Is that correct? That's what it seems you are > : saying. > > Yes, that seems correct. > > Again, though, it seems too limiting to me. This > example fails because perl doesn't see the return of > foo() as two scalars. > I stared at this code below for about 10 minutes before I understood what was going on, why one failed and one worked...my response to that would be, of course! you're passing literals, not scalars to anchor(), but you're prototyping anchor() to receive literals. See, if I saw some code where anchor() was used twice, once where it received scalars, and another when it received literals or hashes, or arrays, I'd be so confused. > sub anchor($$); > > print anchor( '/perl/', 'Learning Perl' ); # works > print anchor( foo() ); # fails > > sub anchor($$) { > my( $href, $name ) = @_; > return qq(<a href="$href">$name</a>); > } > > sub foo() { > return( '/perl/', 'Learning Perl' ); > } > > Note: It turns out that 'link' is a core function, > so I > changed it to anchor() for testing. > gotcha. thanks for the note. > > We would need this use anchor() as is: > > my( $href, $name ) = foo(); > print anchor( $href, $name ); > where $href = /'perl'/ and $name = /'Learning Perl'/, right? > You may find that warm and comfy. ...like a teddy bear from FAO Schwartz. > I find it a > pain > in the ass. TIMTOWTDI. > I never saw the benefit of passing literals, which might explain it. > How about a quote from 'perltooc' by Tom > Christiansen: > > "Perl believes in individual responsibility rather > than > mandated control. Perl respects you enough to let > you > choose your own preferred level of pain, or of > pleasure. Perl believes that you are creative, > intelligent, and capable of making your own > decisions- > -and fully expects you to take complete > responsibility > for your own actions." > I've read this before. I believe I read it the first few days, this, and the horribly complex-looking syntax nearly turned me away from perl. If I could have done all my fun programming ideas in C, I'd never have touched a perl book...Oddly enough, substitute 'C' for 'Perl' in the quote above, and it sounds like the mantra from my first programming book, and professor. But that's an aside. > > : > I agree. However, that shouldn't be the goal > : > (in perl) for a beginner. It is possible, but it > : > requires the knowledge you'll obtain by using > some > : > data structures. > : > : I'm not sure what you're saying here. > > You could achieve your goal of programming with > only subroutines by using objects. In perl an object > is > (normally) a blessed reference to a data structure. > IMO, the more you already understand data structures > in > perl the easier it will be to move toward objects in > perl. > > Gotcha. This makes sense. <snip> > I had the same problem with the documentation. > It > is easier now, but the first few months were very > frustrating. I hate the way perlfunc is laid out. I > added an alphabetical function listing to it, just > for > looking up unfamiliar functions I find in programs. > Heck, if I could copy and paste from my DOS window to Word, then, I'd do that for every time I had to look up something on perldoc. I'm just flabbergasted that perldoc isn't on the web... > Oh, sure delete the one below! Make /me/ go look > it up! :) > > In that script I am passing the file handle DATA > to > a subroutine. If I have strict 'subs' turned off, I > could use this and everything would be fine: I think I understand now. I'm going to go and see if I can't apply some of this to my program. It does everything I want now, I just want to clean it up and get it into separate subroutines. thanks, -stu __________________________________ Do you Yahoo!? Yahoo! Mail - More reliable, more storage, less spam http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>