415 Posted Topics

Member Avatar for mibushk

[QUOTE]Now I have an issue I have to go through this folder structure and insert a file delete_me txt is yhe lowest level, and I have many lowest levels.[/QUOTE]By "lowest level folder" do you mean any folder that does not have sub-folders?

Member Avatar for d5e5
0
414
Member Avatar for lifeworks

[QUOTE=lifeworks;1187744]Hi Im trying to pull out a list of meetings, and the associated number of comments attached to each meeting. Comments are assigned a category (ie meetings) and a linkid (the uniqe id of the meeting) - Im using this query, buts its cutting out all meetings that don't have …

Member Avatar for d5e5
0
83
Member Avatar for samready

[QUOTE]You can always use an array reference, in curly braces, in place of the name of an array. For example, "@{$aref}" instead of @array. (from [URL="http://perldoc.perl.org/perlreftut.html"]perlreftut[/URL]) [/QUOTE]Declare $v as a scalar variable to contain a reference to an array where you can store multiple values. [CODE]#!/usr/bin/perl #HashofArrays.pl use 5.006; use …

Member Avatar for d5e5
0
1K
Member Avatar for terrylau77

[CODE]#!/usr/bin/perl #ElementsIn3Arrays.pl use 5.006; use strict; use warnings; my @a1 = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9); my @a2 = (1, 2, 3, 4, 6, 8, 10, 12, 14); my @a3 = (1, 2, 3, 5, 7, 9, 11, 13, 15); my %h = (); my …

Member Avatar for d5e5
0
151
Member Avatar for Vandithar

It depends what you mean by difference. Your question (but not the Perl script you showed us) implies that by 'difference' you mean the difference between the size of the array having the most elements minus the size of the array having the least elements. If that is what you …

Member Avatar for d5e5
0
606
Member Avatar for wildgunman

[iCODE]$brcount++ while $data =~ /(file for bankrup)|(file for chapter)/gi;[/iCODE] This assumes that those two phrases will never span across two lines. Is that correct? If so, then you don't need to consider appending two lines together to do each match.

Member Avatar for d5e5
0
122
Member Avatar for MadSkyrim

[QUOTE=MadSkyrim;1178903]Hi all, I need a perl script that can open files (given in command line arguments) and extract/print out any dates or times found in it. The format of the dates and times can be any reasonable format. The problem I have is I don't know how to print out …

Member Avatar for MadSkyrim
0
173
Member Avatar for odubhthaigh

[CODE]#!/usr/bin/perl #CheckFilesExist.pl use 5.006; use strict; use warnings; my $directory = '/home/david/Documents'; open (my $fh, '<', 'files.txt'); while (<$fh>) { chomp; if (-e $directory . '/' . $_) { print "***FOUND*** $_ \n"; } else { print "***NOTFOUND*** $_ \n"; } }[/CODE]

Member Avatar for d5e5
0
288
Member Avatar for Manny7

With the bundling option, whether the parameter is entered with one or two dashes does make a difference. For example:[CODE]#!/usr/bin/perl #OneDashOrTwo.pl use 5.006; use strict; use warnings; use Getopt::Long qw(:config bundling); my ($verbose, $get, $v, $g); GetOptions( "verbose" => \$verbose, "get" => \$get ); print "verbose = $verbose\n"; print "get …

Member Avatar for Murtan
0
187
Member Avatar for wildgunman

[QUOTE=wildgunman;1173234][...]What is the meaning of the local declaration in this case, and what does encapsulating the code segment do (if anything)? I get the comment that I am removing the end of line character, but I don't know how it's working.[/QUOTE]The example code modifies the Perl special variable that contains …

Member Avatar for d5e5
0
149
Member Avatar for flashkarni

[CODE]#!/usr/bin/perl #PrintArraysBad.pl use 5.006; use strict; use warnings; my @genres = qw(Action Adventure Animation Biography Bollywood Comedy Crime Documentary Drama); my @languages = qw(English French Spanish Greek German Dutch Esperanto); print_line(@genres, @languages); sub print_line { # @_ now contains the following list: print "You passed the following list of scalar …

Member Avatar for d5e5
0
131
Member Avatar for john_prince

I borrowed sample data (but not the program) for the following from a [URL="http://perlmeme.org/tutorials/parsing_csv.html"]Parsing CSV tutorial[/URL]. The tutorial recommends using the [ICODE]Text::CSV[/ICODE] module, which you may want to do if the "name" field is not the first field of your records. [CODE]#!/usr/bin/perl #Names2Long.pl use strict; use warnings; $_ = <DATA>; …

Member Avatar for d5e5
0
95
Member Avatar for Vandithar

Did you try ppm before you set the http_proxy environment variable? When I was using Windows Vista Home Premium 32-bit I used ppm without knowing anything about an http_proxy and it connected OK, probably because I don't have a proxy server. Since you say you don't have a proxy server …

Member Avatar for d5e5
0
378
Member Avatar for Manny7

[code]#!/usr/bin/perl use 5.006; use strict; use warnings; foreach (@ARGV) { if (m/^--/) { print "$_ starts with two hyphens.\n"; } elsif (m/^-/) { print "$_ starts with one hyphen.\n"; } }[/code]

Member Avatar for Manny7
0
108
Member Avatar for perly

I tried Murtan's version (posted yesterday March 8) of the script. Here's how it looked when I ran it in Terminal: [CODE=text]david@david-laptop:~$ cd /home/david/Programming/Perl david@david-laptop:~/Programming/Perl$ perl SearchFile.pl Enter reaction name for searching:A1_HTTT24 Enter reaction name for searching:B3_PGAI1 Enter reaction name for searching: Given Key isn't found in the file david@david-laptop:~/Programming/Perl$ …

Member Avatar for perly
0
127
Member Avatar for gmxwilliam

One way to accomplish the first three tasks:[CODE]#!/usr/bin/perl use strict; use warnings; use Math::Complex; my @atoms; #For testing, I like to read from the __DATA__ section at the end of the program. #If you prefer, you can do the following instead #open FH, '<', 'somefile.txt' or die $!; #and read …

Member Avatar for d5e5
0
133
Member Avatar for abdolah

[QUOTE]Note that glob will split its arguments on whitespace, treating each segment as separate pattern.[/QUOTE]from [URL="http://perldoc.perl.org/functions/glob.html"]http://perldoc.perl.org/functions/glob.html[/URL] Instead you can use the File::Glob module to override the behaviour of Perl's built-in glob function.[CODE]#!/usr/bin/perl use 5.006; use strict; use warnings; use File::Glob ':glob'; my @files = </home/david/Programming/untitled folder/*>; foreach (@files) { print …

Member Avatar for d5e5
0
97
Member Avatar for aaegcm

[CODE]#! /usr/local/bin/perl use warnings; use strict; my ($gene, $pos, $d, @descs); #program to print one gene per line with all the ontologies while (<DATA>) { chomp; if (!defined $gene or m/^$gene/) { #Never mind } else { @descs = printsummary($gene, $pos, @descs); } ($gene, $pos, $d) = split(/\s+/); push (@descs, …

Member Avatar for aaegcm
0
100
Member Avatar for Vandithar

I ran your script and didn't get any error. I added some print statements to see the content and added another [ICODE]$mechanize->get[/ICODE] to get a different page. They both downloaded in about a second and the output looks complete to me. Is it working for you now? Perhaps the servers …

Member Avatar for d5e5
0
252
Member Avatar for letlet_pogs

Convert the string into a list of characters. Convert the list into a set whose members are unique characters in the list. Then print the length of this set. [CODE]>>> str1 = "abcdeb"; >>> str1 'abcdeb' >>> charset = set(list(str1)) >>> len(charset) 5[/CODE]

Member Avatar for lrh9
0
120
Member Avatar for Tops
Member Avatar for d5e5
-1
115
Member Avatar for john_prince

For example, if your file were called "logins.txt" and contained data like this:[CODE=text]20100217 11:05:18 0da0fbd0 <EDMV:NOTES> From MV Modify <uid=PY1011,ou=Internal,ou=people,dc=eis,dc=example,dc=com> 20100218 11:07:20 0da0fbd0 <EDMV:NOTES> From MV Modify <uid=PY1014,ou=Internal,ou=people,dc=eis,dc=example,dc=com> 20100219 11:09:22 0da0fbd0 <EDMV:NOTES> From MV Modify <uid=PY1011,ou=Internal,ou=people,dc=eis,dc=example,dc=com> 20100220 11:11:24 0da0fbd0 <EDMV:NOTES> From MV Modify <uid=PY1014,ou=Internal,ou=people,dc=eis,dc=example,dc=com> 20100221 11:13:26 0da0fbd0 <EDMV:NOTES> From MV …

Member Avatar for d5e5
0
137
Member Avatar for akaspro

That sounds like a lot of work. This may get you started on Step number 1. I'm assuming the text files contain only file names (one per line) between double quotes. If they contain other text as well you may have to fix it to skip the unwanted text. My …

Member Avatar for akaspro
0
95
Member Avatar for vesnushka

See comments in the following where I modified your statements to avoid the errors and warnings you were getting. I still get a runtime error because the data file I use doesn't contain the same data as your file.[CODE]#!/usr/bin/perl -w use strict; my ( @file, @f, $f, $i ); #Declare …

Member Avatar for vesnushka
0
319
Member Avatar for sniperx99

Good answer but permit me to suggest a minor change to the above example.[CODE]#!/usr/bin/env python #argecho.py import sys if sys.argv: print "The name of this program is:",sys.argv[0] print "The first command line argument I received is:",sys.argv[1] print "The second command line argument I received is:",sys.argv[2][/CODE]

Member Avatar for d5e5
0
476
Member Avatar for john_prince

I don't have a script that does it but if you create and show us an example with a few correct and incorrect phone numbers I'm sure somebody could help you make a script that prints all the correct and / or the incorrect lines separately. We need to know …

Member Avatar for d5e5
0
83
Member Avatar for mvignesh31

As Salem says, redirect the output to a file. For example, lets say I have a script called "my_program.pl" that prints output onto the screen. If I want to have that output go into a file instead, so I can open it with Notepad or some other program, I would …

Member Avatar for onaclov2000
0
115
Member Avatar for Mobius1234

Once you have the data in your arrays you can print them like this: [CODE]#!/usr/bin/perl -w use strict; my @numbers = (1, 2, 3); my @names = ("Sachin", "Sehwag", "Yuvraj"); print "Cricketer's name and the corresponding number are\n"; while (@numbers) { my $num = shift(@numbers); my $name = shift(@names); print …

Member Avatar for onaclov2000
0
119
Member Avatar for mvignesh31

The tr/// operator replaces individual characters with individual characters. It cannot be used to replace one character with three characters. You can write a little Perl script to translate single character codes to triple character codes but tr/// does not do it. See [URL="http://www.daniweb.com/forums/thread251231.html"]this thread[/URL] where [B]vignesh31[/B] asked the same …

Member Avatar for mvignesh31
0
246
Member Avatar for sbedaniweb

[CODE]<html> <head> <script type="text/javascript"> function Calculate(num1, num2) { var total = num1 + num2; alert(num1 + " plus " + num2 + " makes " + total); } </script> </head> <body> <form> <input type="button" value="Click to calculate" onclick="Calculate(8, 4)" /> </form> <p>Clicking the above button calls a function that calculates …

Member Avatar for d5e5
0
77
Member Avatar for jaybstory

My platform is Windows and there happen to be some files whose filenames end in '.txt' in the current directory. Some of them are larger than 3,000 bytes.[CODE]#!/usr/bin/perl -w use strict; #Get list of filenames ending in .txt, test for file (not directory) attribute # and test that file size …

Member Avatar for d5e5
-1
112
Member Avatar for Vindhyaauri

[CODE]#!/usr/bin/perl -w use strict; my $printed = 0; #Boolean switch to indicate good data have/have not been printed while( <DATA> ) { chomp; if (m/^\s{3} #The line should begin with at least three spaces (:? #Start of a non-capturing group (space or hyphen) \s #either another space | #or \- …

Member Avatar for Vindhyaauri
0
190
Member Avatar for jaybstory

I wouldn't want to try reading sequentially from a file and appending to it within the same loop. Instead I would read from one file and print output into a new file opened for output. After you have read through your input file and written everything you want to the …

Member Avatar for jaybstory
0
103
Member Avatar for Davo1977

Before the [ICODE]$filename = <STDIN>;[/ICODE] statement you need the following statement: [ICODE]my $filename;[/ICODE] to declare the $filename variable. That should stop the "Global symbol "$filename" requires explicit package name..." warnings.

Member Avatar for d5e5
-1
243
Member Avatar for SergioQ

[QUOTE]Currently I use this: [ICODE]$value =~ s/\D//g;[/ICODE] I simply need to modify it so that anything after SDCSDC is dropped, whether it's a number or not. Is this possible in RegEx?[/QUOTE]You can modify the RegEx you were using from [ICODE]s/\D//g;[/ICODE] into [ICODE]s/[COLOR="Green"](SDCSDC.*$|[/COLOR]\D[COLOR="green"])[/COLOR]//g;[/ICODE][CODE]#!/usr/bin/perl -w use strict; #Here is my guess of …

Member Avatar for d5e5
0
169
Member Avatar for Krstevski

Something like this? [CODE]>>> import os >>> print os.listdir(".") ['DLLs', 'Doc', 'include', 'Lib', 'libs', 'LICENSE.txt', 'NEWS.txt', 'python.exe', 'pythonw.exe', 'README.txt', 'Scripts', 'tcl', 'Tools', 'unicows.dll', 'w9xpopen.exe'] >>> print os.path.getsize("readme.txt") 56189 >>> print (os.path.getsize("readme.txt")) < 10000000 True >>> [/CODE]

Member Avatar for Krstevski
0
101
Member Avatar for vignesh31

I don't think it can be done with the [iCODE]tr///[/iCODE] operator. Can you use a hash table instead?[CODE]#!/usr/bin/perl -w use strict; my %hash = ( 'a','ala', 'r','arg', 'n','asn', 'd','asp', 'c','cys', 'e','glu', 'q','gln', 'g','gly', 'h','his', 'i','ile', 'l','leu', 'k','lys', 'm','met', 'f','phe', 'p','pro', 's','ser', 't','the', 'w','trp', 'y','tyr', 'v','val'); print "$hash{'h'}, $hash{'w'}, and so …

Member Avatar for d5e5
0
226
Member Avatar for voolvif

Call the [ICODE]findall[/ICODE] method instead of [ICODE]search[/ICODE] to get an array of matches. [CODE]def matchmyip(line): if ippattern.search(line): print ippattern.findall(line) import re ippattern = re.compile(r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b") if __name__ == "__main__": s = "1999-08-01 00:00:00 212.67.129.225 - W3SVC3 PROWWW01 194.128.73.195 GET /entrance/V0_1/default.asp bhcd2=933465599 302 0 497 396 15 80 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+4.01;+Windows+95;+FREESERVE_IE4) bhCookie=1;+ASPSESSIONIDGGGGGRDN=PPLCJMKDDJBMPIMEAEDPIJGF -" …

Member Avatar for voolvif
0
3K
Member Avatar for jrw89

I realize your question is about object creation and use, about which I know little, but permit me to add an FYI about navigator.appName: When I tested Airshow's code in my browser (Chrome) I noticed that the property you are testing, [B]navigator.appName[/B] returns 'Netscape' when run in Chrome. I don't …

Member Avatar for jrw89
0
127
Member Avatar for deonis

Have you tried [ICODE]# -*- coding: utf-8 -*-[/ICODE]? According to [URL="http://www.amk.ca/python/howto/unicode"]this Unicode HOWTO page[/URL] the UTF-8 encoding can handle any unicode code point. As [B]vernondcole[/B] says, when testing you can't rely on IDLE or DOS to display the characters correctly, no matter what encoding you use. To test, write the …

Member Avatar for deonis
0
209
Member Avatar for Vindhyaauri

Here is one way to read and print the first record from a file whose name has been passed as an argument from the command line or shell that invokes the Perl program. [CODE]#!/usr/bin/perl -w use strict; #readfile.pl my $filename = shift @ARGV; #Returns the value of the first parameter …

Member Avatar for d5e5
0
107
Member Avatar for jen140

[CODE]#!/usr/bin/perl -w use strict; my $string = "#324423asdd asd 'BecamePosters' "; if($string =~ m/('[a-zA-Z]{1,40}')/) { #Put parentheses around what should be $1 print "ok!\n"; print $1; } else { print "not ok!\n"; } [/CODE]

Member Avatar for jen140
0
101
Member Avatar for chrisname

I don't have bash but when I tested your Perl script from the Windows command line (after copying an html file into the current directory it worked -- until it died because I don't have a readFile subroutine. But the point is that I didn't get the "$0: no existing …

Member Avatar for chrisname
0
152
Member Avatar for vsagarmb

I don't know. I'm sure you've googled and I've googled and can't find any struct format argument that allows you to pack a unicode string. What you could do is encode the unicode string into an 8-bit string, which the 's' argument will accept and allow you to pack. Which …

Member Avatar for d5e5
0
176
Member Avatar for harpalss

[QUOTE]Say i searched for abasement, i would like the output to be: abasement abasements abases[/QUOTE]As woooee says, you don't have to use regex for this but if you do use it you can modify your first program as follows:[CODE]#!/usr/bin/env python import re f = "fsp.txt" search_term = "abasement" search_term = …

Member Avatar for d5e5
0
133
Member Avatar for lalsumit

This program prints out whether or not each line in the file of protein names occurs in the data file.[CODE]#!/usr/bin/perl -w use strict; #FindTextInFile.pl my ($names, $data) = ("ProteinNames.txt", "ProteinData.txt"); open (FILE1, $names) || die; open (FILE2, $data) || die; undef $/; #Enter "file-slurp mode" by emptying variable indicating end-of-record …

Member Avatar for d5e5
0
360
Member Avatar for Vindhyaauri

When the original poster says read all the data for all the atoms into an array it sounds like an array of arrays. There is no such thing in Perl but you can get the same result using an array of references to arrays. There are tutorials such as [URL="http://perldoc.perl.org/perlreftut.html"]http://perldoc.perl.org/perlreftut.html[/URL] …

Member Avatar for d5e5
-1
439
Member Avatar for ffs82defxp

%s Serves as a placeholder for a string value that will be supplied with values placed after the last % character in the print statement. Likewise, %d serves as a placeholder for a signed integer decimal value. For example: [CODE]qtylist = [5, 7, 3, 11, 2] unitlist = ['bottles', 'flocks', …

Member Avatar for vegaseat
0
777
Member Avatar for drjay1627

I think I would start by combining all four arrays into one array. Then sort it and the highest priority element for each user will be at the top of each group of elements starting with that user. Then I would loop through the sorted array, printing only the first …

Member Avatar for d5e5
0
120
Member Avatar for ajay_p5

Many of the city and country values in the city_lan.txt have a trailing space character, whereas the city and country values in your address_out.txt input file do not have trailing spaces and so don't match.

Member Avatar for d5e5
-1
142

The End.