Similar Threads:
1.reading file and storing information of lines with varying length
Hi!
I have a problem with a file. It looks like this
;r;information;more_info;1;key1;value1;
;s;more;more;2;key1;value1;key2;value2;
;t;info;and;4;key1;value1;key2;value1;key1;value3;key2;value4
I have to extract the information in key and value of each line and
compare it to some information in another file.
I would like to read the file and store the key;value pairs into a hash
and then compare it later on with the other information I have.
As you can see (hopefully) in my example (i.e. line 3) I have some keys
that are used twice (or more often). My suggestion would be an hash of
arrays.
I think in the end it should "look" like this: (for line 3)
%name_of_hash = (
key1 => ["value1"], ["value3"],
key2 => ["value1"], ["value4"]
);
The file uses ";" as a delimiter and in field 4 you have information
about how many key;value-pairs there will be.
I hope I could make myself clear about the problem. I want to read a
file line by line and compare it with some other file. But at the
moment I don't know how to store the information in a hash!
If someone had an idea that would be great!
Greetings
Chris
2.varying hyperlink effects on one page
I have several types of text hyperlinks on one page, all
on differing backgrounds. I would like their behaviour
(alink, vlink etc) to be different aacording to their
background. eg blue link on white background and white
link on blue background.
I have an external css for the page in which the
underlining (text decoration) is switched off.
I am using FP 2003.
Can anybody help please?
3.$sth->bind_columns() with varying amount of columns
I am making a subroutine to handle all the communication with the SQL-
server, however, i bumped into a problem. The thing is that depending
on which table im querying, the amount of columns in return isn't
alwaways the same, so $sth->bind_columns(\$field_1, \$field_2, \
$field_3) will not work when it's accessing a table with anything but
3 columns. I tried simply $sth->bind_columns(\@fields), but the array
still counts as only 1 ref. So... is there a way to:
a) do a workaround, to somehow use the array like that?
or:
b) check between execute() and bind_columns() how many columns i
should expect?
I've been scratching my head over this all day, and the coffee isn't
doing the trick anymore, so feedback and tips would be really
appreciated.
Thanks in advance.
-Kristian
4.Varying a Latitude/Longitude
A while ago while I was in the Army I co-wrote an exercise SIGINT
generator with a friend. We made a mess of a few functions called
VaryLat and VaryLong. The functions basically took in two arguments: a
Latitude or Longitude and an amount to vary it by(in seconds). The
second parameter could be any number positive or negative. The real
issues started rising when we figured out that crossing over either the
90' mark or the 180' mark was throwing off our numbers. The functions
turned out to be very long seeing as how neither of us was very
experience with Perl at the time. I wish I had the code to post to show
how messy this thing was but seeing as how it was on a Top Secret//SCI
machine security protocols made if impossible to bring a copy of this
source home at the time. Basically I was wondering if anyone else has
had this particular problem and came up with a good solution. It's been
bugging me ever since I wrote the stupid code. The function prototype
was something like this: VaryLat($theLatitude,$varyAmount).
5.URI queries with varied amounts of named values
I'm looking for some assistance from the perl folk out there. I am a
perl hack who writes a few scripts a year in perl only when needed.
This seems like a job best suited for perl (most likely a hash) but I
am fumbling around more then I would like to be. I'm sure this is
very simple for anyone well versed in perl.
Objective:
Take a list of named values and put them into a CSV file. When there
isn't a named value there should just be an empty CSV slot. There
might also be some entries on the same line that are somewhat
duplicated, where if there is one entry it should always trump the
other. The CSV file will always have 7 possible entries in the CSV.
language,format,country,zip,category,ua,id
Problem:
The named values vary by line so there is never just X per line. Some
will have just X, some will be X+1, X+5, some will be empty, etc.,
etc.
Example file:
l=en&format=xhtml
format=xml&country=US&ua=Mozilla
l=sp&zip=00000&category=books
l=en&format=xml&id=xyz
l=fr&country=US&alt-country=CA # in this case we want the alt-
country to populate the country field
Example output:
en,xhtml,,,,,,
,xml,US,,,Mozilla,
sp,,,00000,books,,
en,xml,,,,,xyz
fr,,CA,,,,,
I have tried playing around with the URI perl module but haven't had
much luck. I have also made some attempts on my own but I am just not
getting things right. I know this is probably better suited to a hash
but I am very hash illiterate. I can perform basic functions in
hashes and do simple stuff but I don't play around with perl enough to
have gotten any better.
foreach (@DATA_SET) {
next unless /\S/; # strip out blank lines, i.e. no named
values
# print "$_\n";
#$format = m/format=xml/;
#my $format =~ /format=xml/;
#print $_;
#print "$format\n";
}
I also tried pushing the results to another function and doing some
work there but it didn't go well as you can see from how I ended up
completely commenting it out.
#sub string_analysis {
#my (@DATA_RESULTS) = @_;
#@DATA_RESULTS = split(/&/,$_ [0]);
#print "@DATA_RESULTS\n";
#while(@DATA_RESULTS){
# foreach (split/&/,$S)[0]){
# print "$DATA_RESULTS[1]\n";
# }
#}
# push (@SPLIT_DATA_RESULTS = split(/\&/,$_));
#}
#while (@SPLIT_DATA_RESULTS) {
# print "$_\n";
#}
#my @DATA_STRING = split /&/, @fields[9];
#print "@DATA_STRING[1], @DATA_STRING[2], @DATA_STRING[3],
@DATA_STRING[4], @DATA_STRING[5], @DATA_STRING[6], @DATA_STRING[7],
@DATA_STRING[8]\n";
#}
Any help would be greatly appreciated.
6. Sorting Numberic keys in a hash array - with varying number lengths.
7. String Length for password length testing?
8. How to get length of string? length() problems