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

Hi there, I don't agree: this isn't easy code :)
unless (open){ die } else { foo } isn't easy in my opinion. I think open or die; foo; is a lot more readable.
split /|/ will split on either nothing or nothing, and will have the same effect as split //. I think you really meant split /\|/ there.
And a grep might have been a lot easier:
$found = scalar grep { /^\Q$name\|/i } <FILE>;
But still, it's better not to read in the whole file (did you know foreach() slurps the file before processing it?)
while (<FILE>) { $found = 1 if /^\Q$name\|/i }


Anyway... I was just trying to point out that your code wasn't as easy as you thought it was.

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

Replies are listed 'Best First'.
Re: Re: Re: Duplicate data record
by strat (Canon) on Dec 20, 2001 at 19:03 UTC
    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"

      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"

      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