415 Posted Topics
Re: Assuming the example, which I hardcoded and assigned to $data, spans multiple lines and the value preceding the vm name will always be the same, you could try this.[CODE]#!/usr/bin/perl use strict; use warnings; my $data = <<END; Unknown Trap from 192.168.200.35 : Enterprise [1.3.6.1.4.1.6876.4.1] : Specific [3] : Generic [6] … | |
Re: [ICODE]print read_book()[/ICODE] calls the read_book function once. The read_book function does something to each of the lines in the file, so at the end of the first for-loop the variable l (bad name for a variable... looks like a number 1) contains the last line of the file. Then the … | |
Re: I copied and ran your script but couldn't reproduce the error you got. The program kept prompting me with the message "Search for what restriction site for (or quit)?: " as long as I typed and entered some input. When I pressed enter with no input the program exited with … | |
Re: [QUOTE=Anthony Cameron;1402250]Hello, I would like to know if I need to use a regular expression to match the desired substring in order to print out 10 characters of the start codon ATG. My dna sequence is "CATAGAGATA" Thanks for any advice.[/QUOTE] I don't think I understand the question. Your dna … | |
Re: [QUOTE=mitchems;1400811]RTMF... [CODE] use strict; use warnings; my $x=0; while($x<100){ $x++; print "$x\n"; } print "the loop ran $x times\n"; [/CODE][/QUOTE] I wonder if terabyte would mind telling us how to code a few tools, [URL="http://www.daniweb.com/forums/post1395592.html#post1395592"]including calculators[/URL] without printing during a loop.:-/ If I were the OP, I'd mark this one … | |
Someone mentioned in another thread they had found and downloaded [URL="http://search.cpan.org/~adamk/ORLite-1.45/lib/ORLite.pm"]OrLite[/URL], presumably to consider using it to access data in an SQLite database. Since, to use OrLite you need to have the DBI and DBD::SQLite modules installed on your computer as well, I think you could just use DBI to … | |
Re: My platform is linux so I'm not the one to say how to install from CPAN to Windows, but have a look at [URL="http://www.daniweb.com/forums/post1369660.html#post1369660"]http://www.daniweb.com/forums/post1369660.html#post1369660[/URL] which is by [URL="http://www.daniweb.com/forums/member488285.html"]mitchems[/URL] about installing Statistics::Descriptive on Windows. His advice would probably apply to installing Statistics::Lite as well. Just copying the module into your bin … | |
I know next to nothing about statistics so tried Statistics::Basic because it seemed easy to use. Then I tried Statistics::Descriptive because it has functions that Statistics::Basic lacks. What I did not expect was to get a different result when calculating Standard Deviation using Statistics::Descriptive than when using the other module … | |
Re: To find out if the effect of push differs from the effect of unshift, try them both and see.[CODE]#!/usr/bin/perl use strict; use warnings; my @pusharray = ('original', 'contents'); push @pusharray, $_ foreach(1..10); print "array contains @pusharray\n"; my @unshiftarray = ('original', 'contents'); unshift @unshiftarray, $_ foreach(1..10); print "array contains @unshiftarray\n"; [/CODE]Output:[CODE=text]array … | |
Re: [QUOTE=Borzoi;1391632]Why would you not want to use [icode]%word%[/icode]? With your way, if you have something like "Harry Potter and the Chamber of Secrets" and the person searches for "Chamber of Secrets" then no result would be returned. If you have code to ignore "The" every time, then if someone searches … | |
Re: [CODE]#!/usr/bin/perl #score_many_mutant.pl use strict; use warnings; my $sequence='A G G G C A C C T C T C A G T T C T C A T T C T A A C A C C A C A T A A T T T T T A T … | |
Re: Could you have more than one prod_id per proposal-evaluator group? If so, which prod_id do you want... first, last, greatest, least? Or maybe you should group by prod_id in addition to PA.proposal_id and PA.evaluator_ID. | |
Re: I would read it as "If value of $line starts with [COLOR="Green"]Referers[/COLOR] followed by optional whitespace characters (zero or more) followed by [COLOR="Green"]=[/COLOR] followed by optional whitespace characters (zero or more) followed by one or more other characters (note the ? lazy quantifier) followed by optional whitespace characters (zero or … | |
Re: Please wrap your script (or the perl code you wish to show us) in `[CODE]Your program goes here[/CODE]` tags. You say part of the script is giving you "the issue". Can you show us the issue, preferably by giving an example of an input sequence, an example of the output … | |
Re: Try this modified version of one of [URL="http://www.daniweb.com/forums/member854905.html"]dch26[/URL]'s solutions:[CODE]#!/usr/bin/perl use strict; use warnings; my $df_stats = qx{df /home/}; #I don't have dir called /compare/ so I used /home/ my @fields=split(/\s+/,$df_stats); #Split on one or more whitespace characters #Can we assume first 6 fields are column headers? #If so, instead of … | |
Re: To fix it, add a newline character immediately after FOOTER. Like this:[CODE]#!/usr/bin/perl use strict; use warnings; print <<FOOTER; </body> <! --end tag for main page section --> </html> <!-- end tag for entire HTML page --> FOOTER #Had to add newline after FOOTER #to avoid "Can't find the string terminator..." … | |
Re: Yes.[CODE]#!/usr/bin/env python filename = '/home/david/Programming/Python/data.txt' f = open(filename) for line in f: if line.startswith('apple'): print line [/CODE] | |
Re: I don't have Windows 7 but the code you posted has a syntax error.[CODE]#Root.geometry("%dx%d")%(RWidth,RHeight) #_tkinter.TclError: bad geometry specifier "%dx%d" #Replace with the following line Root.geometry("%dx%d+0+0" % (RWidth, RHeight))[/CODE] | |
Re: Please start a new thread to ask your question instead of replying to a three-year old thread. When you post your question, please include your script, invoice.pl, wrapped in `[CODE]Your invoice.pl script goes here[/CODE]` tags. We can't help you with this kind of error unless we know what you are … | |
Re: The following statement fails to specify the file open mode. The default mode of read only is assumed. [iCODE]open(OUT,"LuContig091010RNAcomp.fa")or die $!;#No redirection character so file is opened in read mode[/iCODE] I prefer the 3-argument version of the open, like this: [ICODE]open( OUT, ">", "LuContig091010RNAcomp.fa" ) || die "Can't create output … | |
Re: [QUOTE=Asset;1373417]@snippsat Thank-you, but can you please will this work if i'm reading the file from a list? My project requires me to create a def function that can convert the list of numbers into a number before I can get the average. Btw am I able to put anything in … | |
Re: Please wrap your program in [noparse][CODE]Your program goes here[/CODE][/noparse] tags. Otherwise we can't see how the lines in your program are indented and have to guess. | |
Re: The script doesn't appear to read the cookie. In your error log (or whatever file STDERR writes to) you may find something like "Use of uninitialized value $count in concatenation (.) or string at..." | |
Re: I have Python 2.6 and it worked fine for me without my uncommenting [iCODE]#n = fin.readline()[/iCODE] or anything else. I made no changes except the file path and it showed me a word count for the my file (not the constitution but some other file in my folder). When it … | |
Re: Please try this approach.[CODE]#!/usr/bin/perl use strict; use warnings; my (@in, @out); while(<DATA>){ chomp; push @in, [split(/\t/)];#Build an array of arrays } my $prev_aref; foreach my $aref (@in){#foreach array reference if (!defined($prev_aref) or $$aref[1] ne $$prev_aref[1] or abs($$aref[2] - $$prev_aref[2]) >= 250){#At least 250 away from prev loc push @out, $aref; … | |
Re: [QUOTE=Anthony Cameron;1368267]How do you write a perl script to determine the number of measurements, average, variance, standard deviation? This is the script that I have so far and it is not working. my @data = (6, 9, 7, 23, 30, 18); my @data2 = (10, 5, 8, 11); my @data3 … | |
Re: Since you want to use text from a file to construct a regex pattern, you need to remember to escape the characters in this text that would otherwise have special significance to regex. You can use the quotemeta() function to do this.[CODE]#!/usr/bin/perl use strict; use warnings; #You can open a … | |
Re: [QUOTE=richieking;1364611]You want simple one. Check this out. [CODE] my @S=("hello","ben","foo",,"","bar","rose","world","foo",'loo'); foreach (@S) { print(s/\",'*//,$_); print "\t"; } ## OUT PUT hello ben foo bar rose world loo [/CODE][/QUOTE] In the above example there is nothing to remove. You will find that replacing [ICODE]print(s/\",'*//,$_);[/ICODE] with a simple [ICODE]print;[/ICODE] will give the … | |
Re: For your first question, try this (not tested)[CODE]SELECT course, cnt FROM ( SELECT course, count( * ) AS cnt FROM uniresults WHERE symbol = 'F' GROUP BY course) `b` WHERE cnt = ( SELECT min( cnt ) FROM `course_count` )[/CODE] | |
Re: I would suggest an easier approach than the one you are taking. Read the file one line at a time. Take the first three characters at the beginning of each line and concatenate them all in one variable, so you will end up with a variable having the value [iCODE]'ABCXYZMNOPODNFYPORLKMABCXYZMNOEFGNFYPORLKMABCXYZMNOABCXYZMNOEFG'[/iCODE]. … | |
Re: Pretend your subquery in parentheses is just another table. Give it an alias by putting a name after it (in my example I used `a` as an alias.) Your ORDER BY for your main query (which contains the subquery) goes at the end. Something like this:[CODE]SELECT x, y, z FROM … | |
Re: I don't understand why you need to convert the hex number into binary before using it to make a decision. Are these two separate requirements? You need to convert the string to binary AND you need to test the value and take one of 255 possible actions? For your first … | |
Re: I found this incredibly difficult as I've done very little XML. I tried using XPath but don't know enough about XPath. Finally, I tried XML::Simple.[CODE]#!/usr/bin/perl #parse_xml_simple.pl use strict; use warnings; # use module use XML::Simple; # create object my $xml = new XML::Simple; # read XML file my $file = … | |
Re: [QUOTE=mitchems;1353666]I'm not sure that answering a question after 5 years is really effective.[/QUOTE] [iCODE]system("sleep 157784630s");#Wait 5 years[/iCODE]Note: I haven't had time to test this.:) | |
Re: PHP runs on the server so before it can respond to what the user enters in the browser, which runs on the client, the client must post something to the server. Javascript runs in your browser on the client, so it can respond to events such as the user typing … | |
Re: You already [iCODE]open("exercise1.txt", "w")[/iCODE] outside your loop. This creates a new empty file. Good. But you also open the same file in your for loop. Don't do that. Repeating the open statement in 'w' mode for that file recreates the empty output file each time it reads a line from … | |
Re: What is your current working directory when you are running the program? To find out, run the following commands from whatever editor you are going to use to test your program.[CODE]import os print os.getcwd()[/CODE]I suspect that you don't have all the necessary permissions to create and write to a file … | |
Re: I failed to replicate the error running your script on the data you posted. It looks like you have Python version 2.6. I do too (2.6.4 to be exact) so I guess the problem isn't different versions. (Maybe different versions of the csv module?) Also, posting data in quote tags … | |
Re: [QUOTE=Renuka Devi G;1357030]Hello, I am learning perl programming but my problem is iam unable to find how the functions, commands,loops & conditions are working in a programme can anyone help me how to write a programme? what is the logic?[/QUOTE] What is the logic? For example, here is a statement … | |
Re: I've seen that done a lot querying an Oracle database where I used to work. It worked fine. I haven't tried that in MySQL but I can't think of any reason that it wouldn't work. Just keep in mind that if you do this a lot you may end up … | |
Re: [QUOTE=dotmandd;1319907]yeah i already added that to it but it is not working.[/QUOTE]You haven't said yet whether any of your other cgi scripts run on your server. What happens when you run a really simple one? Such as:[CODE]#!/usr/bin/perl #hello.cgi use strict; use warnings; print "Content-type: text/html\n\n"; print "Hello, world!\n"; [/CODE]If that … | |
Re: How about attaching a sample file and telling us what part of the data you want to extract? That way those of us who are not network engineers might understand what you want to do. For example, does your file contain data like the following?[CODE=text].1.3.6.1.2.1.25.3.7.1.1.1537.1 = INTEGER: 1 .1.3.6.1.2.1.25.3.7.1.1.1537.2 = … | |
Re: Python has several kinds of [URL="http://docs.python.org/tutorial/datastructures.html"]data structures[/URL], including lists, tuples, sets, and dictionaries. A dictionary associates unique keys with values and is good for retrieving the value stored for any specific key.[CODE]>>> lights = {'red': 'stop', 'green': 'go', 'yellow': 'go like hell'} >>> print 'red means ' + lights['red'] red … | |
Re: Yes, it works for me after making the change Mike suggested. It keeps the userName after I click on various letters. Does it lose its value for you the first time you click a letter, or only after you click a specific sequence of letters? You appear to have an … | |
Re: Escape the open and close parentheses that are meant as literal characters and enclose the data that should be captured in parentheses to create two capture groups. These two capture groups are referenced in your replacement string as \1 and \2.[CODE]#!/usr/bin/env python import re def main(): expr = '5*pow(a,b) + … | |
Re: What you have in your file are bytes of data. When you read a record from the file you get a string of bytes. If these bytes are supposed to represent text characters, they must have been encoded in some format, such as utf8, before being written to the file. … | |
Re: Here is an example of how to find differences between an older and newer file, using a hash. For simplicity I used ordinary text data, but it should work for csv files as well since you don't need to parse the lines into fields at this point. (You can parse … | |
Re: What is the encoding of your file? Files contain bytes of data, not characters. The bytes represent characters only according to whatever encoding was used to write the data to your file. Ask whoever created your data file what encoding they used. Or, you could attach the file to your … ![]() | |
Re: Near the beginning of the [URL="http://perldoc.perl.org/Getopt/Long.html"]documentation for Getopt::Long[/URL] it says "To distinguish between a bundle of single-character options and a long one, two dashes are used to precede the option name." You would type the following at your command line to run your script.pl [iCODE]perl script.pl --teacher[/iCODE] In every perl … | |
Re: [CODE]#!/usr/bin/perl #parse_file_kv.pl use strict; use warnings; #For convenience I read from DATA section. You can open a file instead. my $save_input_record_separator = $/; #Save original value before changing it undef $/; # enable slurp mode my $file = <DATA>; $/ = $save_input_record_separator; #Restore original value to this global variable $file … |
The End.