- Strength to Increase Rep
- +11
- Strength to Decrease Rep
- -2
- Upvotes Received
- 103
- Posts with Upvotes
- 93
- Upvoting Members
- 57
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Born in Toronto, CANADA. Attended elementary and high school in Smiths Falls, B.A. at University of Toronto in philosophy and psychology. Met and married Franceen in Montreal. Worked as Programmer/Analyst in Montreal and down south in Georgia, USA. Returned…
- Interests
- Reading blogs, books, philosophy, psychology, futurism.
- PC Specs
- HP notebook computerModel: G60-230CAUbuntu 10.04 LTS - the Lucid Lynx
415 Posted Topics
Re: I can't point to an authority to back me up, but my guess is that we discover the one-one vs. on-many relationship by studying the PRIMARY key of the tables in question. Because the values of the primary keys of the two tables do not have to be identical between … | |
Re: [CODE=perl]#!/usr/bin/perl -w #ReplaceBackslashWithSlash.pl use strict; my $myPath = 'c:\perl\test'; # Example string containing backslashes print "\nOriginal string is: $myPath\n\n"; # The following command substitutes backslashes with forward slashes # You need to escape the backslash and slash with backslash $myPath =~ s/\\/\//g; print "Modified string is: $myPath\n";[/CODE] | |
Re: I don't know but you could start by finding your httpd.conf file and having a look at [URL="http://serverfault.com/questions/29942/xampp-on-windows-permission-problems"]this post[/URL] in case the solution to that person's problem throws light on yours. | |
Re: I think you can use pretty much the same list that you used for the simpler problem. All you need to come up with is a formula to calculate the index for each grade. [code=PYTHON] def main(): grade = raw_input("Enter the student's grade: ") index = int(grade)/10 grades = ["F", … | |
Re: Maybe the PHP configuration on the server running your script tells PHP not to display any errors (although I don't see any errors in your script.) Try adding the following line to the beginning of your script: [iCODE]ini_set('display_errors', 1);[/iCODE] [URL="http://www.wallpaperama.com/forums/how-to-display-php-errors-in-my-script-code-when-display-errors-is-disabled-t453.html"]http://www.wallpaperama.com/forums/how-to-display-php-errors-in-my-script-code-when-display-errors-is-disabled-t453.html[/URL] | |
Re: I'll have another look when I get some time but the first thing I'd suggest: [CODE]use strict; use warnings;[/CODE] belong in every non-trivial Perl script. Add them to your script and declare any undeclared variables, such as @sesname, @title1, @all, @title2 and $i. Another general suggestion: when opening files, use … | |
Re: I used to have @david_ellis on Twitter and I thought if I made it shorter people would retweet me more often. (This was before Twitter came up with their new retweet action that doesn't include the posters handle in the character count.) I shortened it to @d5e5 because my first … | |
Re: For a table named 'items':[CODE]update items set itemName = replace(itemName,'/','');[/CODE] | |
Re: The following may not exactly correspond to what you mean by 'numeric' but it will serve as an example of what the Scalar::Util module can do. #!/usr/bin/perl use warnings; use strict; use Scalar::Util qw(looks_like_number); while (my $teststring = <DATA>){ chomp $teststring;#Remove newline character from end of string if (looks_like_number($teststring)){ print … | |
Re: #!/usr/bin/perl use warnings; use strict; my $path = <DATA>; chomp($path); print 'Original path: ', $path, "\n"; $path =~ s/"/'/g;#Replace all " with ' print 'Changed path: ', $path, "\n"; __DATA__ "C:\Users\ABC\XYZ\1.txt" | |
Re: [QUOTE=Ancient Dragon;1570084]The best at what? Best communist country? Might be, I don't know. But I hear people in Russia have very limited food in their stores with long lines to buy anything. That's what I hear from here. >>Could you please explain how this can be when the gap between … | |
Re: Look closely at lines 16 - 17. my $Header; $hash{$Header} = $_; You declare a lexical variable called $Header and assign no value to it, so its value is undefined. Then you use $Header (whose value is undefined) as a key to $hash. In effect you are assigning all the … | |
Re: You may also want to look at the [Bio::DB::Fasta](http://search.cpan.org/~cjfields/BioPerl-1.6.901/Bio/DB/Fasta.pm) module. I haven't tried it but according to the docs it has the following method to extract specific substrings from fasta files: > $raw_seq = $db->seq($id [,$start, $stop]) > Return the raw sequence (a string) given an ID and optionally a … | |
Re: I would create a text file in comma separated values (or tab-separated if you prefer) format extension because I find it easier to write text files. Then you can start up Excel and import the movies_or_whatever.txt file into a sheet using Excel and save it as an Excel file. | |
Re: What data are you trying to read? Please post an example of your input data and some example code showing how you try to read it. I don't know much about XML and nothing about soap but maybe somebody here does and can help you if you provide relevant information. | |
Re: OpenOffice::OODoc looks like the module you need to install and learn how to use. I have no expertise with it so if you don't want to learn how to do it yourself I think you may need to hire a programmer with the relevant experience to write a script that … | |
Re: Scripting makes it easier to do something that we repeatedly do, so what scripting language would serve you best depends on your answer to the question what do you do repeatedly that has several steps, that you would like to do in fewer steps, automatically? As Aristotle said, ["We are … | |
Re: In general I would try to tailor the complexity of the solution and extent of explanation to the apparent knowledge level of the person posing the question. However, figuring out what the poster needs to know is a two-way street. If someone posts a vague and hastily-written question and never … | |
Re: > Any simple ways to get hyperlinks using perl without the HTML table? Yes. What's wrong with the example shown in the [docs](http://search.cpan.org/~gaas/libwww-perl-6.04/lib/LWP/Simple.pm)? use LWP::Simple; $content = get("http://www.sn.no/"); I assume that you want to retrieve the html content from the site refered to in a given hyperlink, right? If the … | |
Re: The following script creates a table (if it doesn't already exist) and saves all the image names (extension included) and the directory names. #!/usr/bin/perl use strict; use warnings; use DBI; use File::Glob ':glob'; use File::Basename; my $dbh=DBI->connect('dbi:mysql:daniweb','david','dogfood') || die "Error opening database: $DBI::errstr\n"; $dbh->do("CREATE TABLE IF NOT EXISTS images (id … | |
Re: You could write your subroutines as values in a hash in your script and then run it from the commandline with the name of your desired function as the first argument on the command line. For example, a script named many_functions.pl #!/usr/bin/perl use warnings; use strict; my %funcs = (thisismyfunction1 … | |
Re: In Perl I would change the value of the special variable representing the input record separator $/ to '!' to read entire records instead of one line at a time. Then you need only one loop within which you can use regex to capture values into variables. #!/usr/bin/perl use warnings; … | |
Re: If you run perl and your script from the command-line interface in a DOS window or a Terminal in linux and print to STDIN then maybe the DOS or Terminal can't print those characters. I think that depends on the platform. However if you print something encoded as utf-8 to … | |
Re: Multi-line records with no record separator make it tricky. As for writing CSV output it's worth installing the [Text::CSV](http://search.cpan.org/~makamaka/Text-CSV-1.21/lib/Text/CSV.pm) module if you don't already have it. #!/usr/bin/perl use warnings; use strict; use Text::CSV; my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attribute. or … | |
Re: > open my $fh, '<', $file1 or die "can't open $file1:$!"; Why do you have statements like the above where I see '<' instead of '<'? Besides fixing the above, mostly all you need to do to get what you want is to switch the filenames, as follows: #!/usr/bin/perl use … | |
Re: If one of 2teez's scripts works for you with the large files, good. Otherwise you could try the following modified version. When working with large files you need to consider memory limitations vs. speed. I think 2teez's scripts make good use of memory but take a bit longer than using … | |
Re: > I face some real problems here. I need a Perl script that can open a text file, read a series of URLs, get the content of the pages and save it to another file. Divide your task into steps, such as: 1. open a text file 2. read a … | |
Re: > suppose my input string is "a*b+c/\/" and I want a Perl regex expression to match it. #!/usr/bin/perl use warnings; use strict; my $x = 'String of 8 words including numbers and letters'; my $y = 'String including characters like a*b+c/\/ plus text'; my $z = 'Some numbers 7, 8 … | |
Re: > Thanks for helping .. could you pls order them time by time. Also they should be from the new time to last time abulut, Do you mean you want them ordered by a combination of date and time? Should 2012-03-16 14:29:54.61 print before (above) 2012-04-23 07:16:21.83 for example? Normally … | |
Re: Start by reading both files into a suitable data structure (see [the data structure cookbook](http://perldoc.perl.org/perldsc.html#HASHES-OF-HASHES)). Then you can read and test values from your data structure to print the details of your report. #!/usr/bin/perl use strict; use warnings; @ARGV = qw(FILE1.txt FILE2.txt); my %HoH; #Hash of hash references while (my … | |
Re: First, always `use strict;` for anything more than a one-liner. Second, indexing of arrays starts at 0, so you will refer to the eighth element in the result of your split as `$whatever[7]`. (Note that `$whatever[9]` is undefined.) Also note that the package global variables $a and $b have a … | |
Re: To answer the first part of your question about removing spaces from the number and reading from four input files: #!/usr/bin/perl use strict; use warnings; @ARGV = qw(PT1.txt PT2.txt YK1.txt YK2.txt); while (my $line = <>){ my @fields = split /\s+/, $line; print @fields[6..8], "\t", $fields[9], ' | ', $ARGV, … | |
Re: 2teez when I run your script and enter Kate when prompted I get no output. No error but no output either. I made a few changes in the loop that builds the hash and now it works OK for me. perllearner007 I couldn't recreate your error but you might as … | |
Re: #!/usr/bin/perl use strict; use warnings; my @array = <DATA>; my ($s_min, $e_max) = (99999, 0); foreach (reverse @array){ chomp; next if m/^\s/; my ($code, $source, $start, $end) = (split)[0,2,3,4]; if ($source eq 'match_part'){ $s_min = $s_min < $start ? $s_min : $start; $e_max = $e_max > $end ? $e_max : … | |
Re: I would read and print every line from the file into a new file, changing the line that matches your first two arguments. If you read the entire file without finding a match then print your new line at the end of your new file. If the new file needs … | |
Re: Your idea of a hash with keys of fruit names and values as array references should be sufficient. In your last script you convert the hash to a hash reference. You don't need a hash reference in this case and it makes the code look more complex when you want … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; my @matrix; while (<DATA>){ chomp; push @matrix, [split]; } foreach my $row (@matrix){ foreach my $cell (@$row){ $cell = no_more_than_1($cell); } } foreach (@matrix){ print join ' ', @$_, "\n"; } sub no_more_than_1{ my $nbr = shift; if ($nbr > 1){ return '1.0'; } else{ … | |
Re: See [Why isn’t there a switch or case statement in Python?](http://docs.python.org/faq/design.html#why-isn-t-there-a-switch-or-case-statement-in-python) | |
Re: The set function gives a set of the unique items in a list. Iterate through that and print the count method of the list for each item. #!/usr/bin/env python def checkForWidthCount(mylist): for x in set(mylist):#Iterate through set of unique list items print x, 'count = ', mylist.count(x) ExampleOfList = [1,2,3,3,3,5,5,5,6] … | |
Re: For this sort of task I would prefer using inplace-edit instead of read-write mode. #!/usr/bin/perl use strict; use warnings; if (@ARGV == 0){ my $filename = 'test.txt'; #So you can use diamond operator and inplace editing push @ARGV, $filename; warn "No file name argument so I assume you want to … | |
Re: Rather than change your long complex script, you can run a second script that takes the resulting file as input, then modifies the spacing and sorts the lines.[CODE]#!/usr/bin/perl use strict; use warnings; my $filename = 'KESIK_SEKTORLER.txt'; open my $fh, '<', $filename or die "Failed to open $filename: $!"; my @file … | |
Re: I can't recreate the problem. did you literally type `which perl-` with a hyphen -? Why not just `which perl`? Are you logged into a remoter server somehow? I don't really understand the question. | |
Re: `my $word=~/DOT\d+/;` attempts to match whatever is in $word and there is nothing in $word at this point in the script. You can store a regex pattern in a variable using the [Regexp-like quote function](http://perldoc.perl.org/functions/qr.html) as follows: `my $word = qr(/DOT\d+/);` | |
Re: [Lexical variables](http://perl.plover.com/FAQs/Namespaces.html#Lexical_Variables) declared with `my` are defined only within the block in which you declare them. In your script you are returning a value in a void context instead of printing it or assigning it to a variable having a scope outside the subroutine. Here is how you would assign … | |
Re: You can read through the first file line by line, and for each line you can check if it represents a required update to the database. It doesn't matter too much that the first file is huge because you only hold one line at a time in memory. However, if … | |
Re: [QUOTE=realoneomer;1436224]Hello Perl Guru's I am playing with two text files using perl but i have been end up after a one day effort and got nothing there fore i have decided to post some thing here for help well here are some details that what actually i want to do … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; my $str = '01010'; #When 10 found, 'lookbehind' to see if 0 precedes it. #If 0 precedes the 10 then capture the 10 #You can do this for repeated matches. my @results = $str =~ m/(?<=0)10/g; print join ', ', @results, "\n"; #If you want … | |
Re: You can read the second file into a hash if the values in the first column are unique. By 'unique' I mean that '153814_at' occurs no more than once in the second file, so you can use it as a key in your hash whose value is 0.09276438. After building … | |
Re: [CODE]#!/usr/bin/perl use strict; use warnings; my $gia = '12tai'; #Capture sequence of digits into one variable, #capture sequence of non-digits into another variable my ($number, $name) = $gia =~ m/(\d+)(\D+)/; print "$number $name\n";#Two values separated by one space[/CODE] | |
Re: I wouldn't call either of them wrong. For multiple inserts in a loop, I prefer the prepare + execute with place holders rather than the do, for a couple of reasons. In theory it makes more sense to prepare the insert statement once outside your loop and then execute it … |
The End.