Learning Perl: 8.1. Matches with m//

Previous Page
Next Page

 

8.1. Matches with m//

We've been writing patterns in pairs of forward slashes, like /fred/. This is a shortcut for the m// (pattern match) operator. As you saw with the qw// operator, you may choose any pair of delimiters to quote the contents. So, you could write that same expression as m(fred), m<fred>, m{fred}, or m[fred] using those paired delimiters, or as m,fred,, m!fred!, m^fred^, or many other ways using nonpaired delimiters. [*]

[*] Nonpaired delimiters are the ones that don't have a different "left" and "right" variety; the same punctuation mark is used for both ends.

The shortcut is that if you choose the forward slash as the delimiter, you may omit the initial m. Since Perl folks love to avoid typing extra characters, you'll see most pattern matches written using slashes, as in /fred/.

Choose a delimiter that doesn't appear in your pattern.[] If you wanted to make a pattern to match the beginning of an ordinary web URL, you might write /http:/ to match the initial "http://". But that'll be easier to read, write, maintain, and debug if you use a better choice of delimiter: m%http://%.[] It's common to use curly braces as the delimiter. If you use a programmer's text editor, it probably has the ability to jump from an opening curly brace to the corresponding closing one, which can be handy in maintaining code.

[] If you're using paired delimiters, generally you shouldn't have to worry about using the delimiter inside the pattern since that delimiter generally will be paired inside your pattern. That is, m(fred(.*)barney) and m{/w{2,}} and m[wilma[/n /t]+betty] are all fine even though the pattern contains the quoting character, since each "left" has a corresponding "right." But the angle brackets (< and >) aren't regular expression metacharacters, so they may not be paired. If the pattern were m{(/d+)/s*>=?/s*(/d+)}, quoting it with angle brackets would mean having to backslash the greater-than sign so that it wouldn't prematurely end the pattern.

[] Remember, the forward slash is not a metacharacter, so you don't need to escape it when it's not the delimiter.

Previous Page
Next Page
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
安装torch和torchvision可以通过以下步骤完成。首先,你需要进入https://download.pytorch.org/whl/torch_stable.html。在这个网页上,你可以找到适用于不同版本和操作系统的torch和torchvision的下载链接。根据你的需求,选择对应的版本并点击下载链接,浏览器会自动开始下载。例如,如果你使用的是Python 3.7和Windows操作系统,你可以找到相应的下载链接并点击下载。\[1\] 在安装过程中,有一点需要注意。之前有人在博客中提到,只需要在https://download.pytorch.org/whl/后面加上自己的CUDA版本号就可以安装。然而,这样安装的是CPU版本的torch,导致torch.cuda.is_available()返回False,无法使用GPU。所以,请确保你下载的是适用于你的CUDA版本的torch和torchvision,以便能够使用GPU。\[2\] PyTorch是Torch的升级版,它是一种强大的深度学习框架,具有优秀的前端和灵活性。相比于其他框架如TensorFlow,PyTorch不需要重复造轮子,易于调试和调试,极大地提高了开发效率。如果你想了解更多关于PyTorch的学习和介绍,可以参考https://morvanzhou.github.io/tutorials/machine-learning/torch/。\[3\] #### 引用[.reference_title] - *1* *3* [windows和mac下python3.x安装torch和torchvision失败的解决方案](https://blog.csdn.net/weixin_42028032/article/details/102496443)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [CUDA 11.7安装pytorchGPU失败解决记录](https://blog.csdn.net/weixin_42888638/article/details/127235202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值