in reply to Re: Re: Duplicate data record
in thread Duplicate data record

Hello juerd,

as it seems to be a cgi script, imho die is more complicated (500-error) than unless with a proper structure.

Thank you for | => \|, since it indeed is wrong.

I know, that foreach slurps in the file at once. I wanted to avoid the game with the invisible variable $_ with while(<FILE>), and don't like while (defined ($_ = <FILE> )), because you have to know a lot about to understand it correctly.

I decided to write the example the way I did because it might be rather clear if you already know another programming language, even if it doesn't look very 'perlish'.

I like your code examples, and in a script maybe I'd write something like that, but for a beginner it might be more complicated because there's so much hidden behind.

Best regards,
perl -e "print a|r,p|d=>b|p=>chr 3**2 .7=>t and t"

Replies are listed 'Best First'.
Re: Re: Re: Re: Duplicate data record
by Juerd (Abbot) on Dec 20, 2001 at 19:09 UTC
    I'm Juerd, not vroom :)

    You used a die() in your unless-block anyway, so your code will also cause a 500 error. I think having structured code when a simple "or die" suffices is overkill...
    I agree on your script being more clear to those who already know another language, but did you learn Perl to code the way you always did? I sure didn't: I learnt perl because I like the perlish way. But that's personal, and I can think of good reasons to code in an unperlish way.

    P.S. There's nothing greater than the invisible $_ game - if you know the rules.

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      Hi Juerd,

      sorry for calling you vroom, I have already changed it.
      With die, I was silly; I wanted to use a print, but haven't :-(

      As I started with perl, I used it like C, because at that time it was the language I used most often. That helped me to get results very early. Then, as I read some books about perl and some other's people code and wrote several programs, over the years developed my own perl-programming-style.

      In my eyes, a way from the already known facts to the new, unknown ones is always best. But about teaching, I should keep my line and do not so many errors ;-)

      Btw: congratulations, monk :-)

      Best regards,
      perl -e "print a|r,p|d=>b|p=>chr 3**2 .7=>t and t"

Re: Re: Re: Re: Duplicate data record
by britney (Acolyte) on Dec 22, 2001 at 03:39 UTC
    Here is my phone.cgi I have a phone.html to call this cgi when they summit it will write to file Data/phone.txt But i really do not want them to add more than one time like:
    mike:miketyson@yahoo.com:123-2323-324 bill:billyong@hotmail.com:434-3213-321 mike:miketyson@yahoo.com:123-2323-324 briney:britney@yahoo.com:343-2322-111 mike:miketyson@yahoo.com:123-2323-324
    It should tell mike is already enter in our database before they write to Data/phone.txt they check to see any mike with the same email and phone or not if the same they give alert. If not then add. Thanks