Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Looking for function similer to member() in SKILL

by Limbic~Region (Chancellor)
on Jun 21, 2005 at 14:33 UTC ( [id://468690]=note: print w/replies, xml ) Need Help??


in reply to Re: Looking for function similer to member() in SKILL
in thread Looking for function similer to member() in SKILL

Zaxo,
I wonder what riz meant by "both @arr & file are big"? I know that demerphq has provided patches to bleed perl for alternation in regexen, but this can get slow quickly in 5.8.x. Ok - let's assume that for some reason a hash isn't an option (order is important) and memory consumption is at a premium already. Is there a way to make it any faster?
#!/usr/bin/perl use strict; use warnings; my @set = qw(one bright day in the middle of the night); my %pos; # Preprocess @set { no warnings 'uninitialized'; vec( $pos{ ord( $set[ $_ ] ) }, $_, 1 ) = 1 for 0 .. $#set; } while ( my $val = <DATA> ) { chomp $val; my $bitstr = $pos{ ord( $val ) } or next; my $i = length( $bitstr ) * 8 - 1; while ( $i-- ) { print "$val\n" and last if vec($bitstr, $i, 1) && $val eq $set +[ $i ]; } } __DATA__ one two buckle my shoe the cat in the hat
I have no idea how well this scales but my guess is it is a failed attempt. I doubt the reciprocal of this solution (indexing file offsets instead) would have been any better. It was a fun experiment anyway.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Looking for function similer to member() in SKILL
by Anonymous Monk on Jun 27, 2005 at 07:52 UTC
    Hello all,
    Thank to all. I found out that there is a perl module member.pm available which should perform the same function as Skill language member().
    Again I am stuck in the loop. I want to print the pair of integer values for only the member of @arr e.g. in this case the pair integer values for Stack3 and Stack5 should be printed. Somehow the member function is reading only the first element of my array.Somebody advice where I am doing wrong?

    Here is my code;
    And here is the file;

    20050627 Edit by ysth: code tags

      Anonymous Monk,
      Please read Writeup Formatting Tips to make your posts clearer in the future. Additionally, you may want to look at perlstyle or Perltidy to make your code clearer. You should also start using strictures and warnings and possibly even diagnostics as they will help you to find problems on your own.

      Now on to specific problems with your code. The next unless /@arr[$index]/ should be using the $ sigil as you are talking about a single element. In fact, this line makes little sense anyway as you are checking to see if the line matches your array, and then you are checking it again by matching using a regex. There is no need to match twice. Of course, this won't work for a couple of reasons - the first is that you are not chomping the line so it will never match because of a newline at the end. The second is that you aren't even reading the file - your while () { ... } should really be while ( <IN> ) { ... }.

      There are more problems but I think you need to take a step back. Try starting out with the smallest piece of working code you can imagine and build on it checking the result each time. The first time it doesn't do what you expect, look there for the problem. For instance - start out reading a file and printing the contents.

      Cheers - L~R

        Hi L~R,
        Sorry I made a mistake posting the message. In my actual code I am reading
        while (<IN>) {...}. Also I tried using chomp but I don't get the right output.

        regards riz.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://468690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found